# Pattern 1: Import the whole moduleimport math# Now use: math.sqrt(16)# Pattern 2: Import specific items from a modulefrom math import sqrt, pi# Now use: sqrt(16)
What’s happening:
import math - brings in the entire math toolbox
from math import sqrt - takes just the sqrt tool from the math toolbox
# Install a packagepip install requests# Install specific versionpip install requests==2.28.0# Install multiple packagespip install pandas numpy matplotlib
Always ensure your virtual environment is activated before installing! This is the #1 source of import errors. If you get “ModuleNotFoundError” after installing, you probably installed to the wrong environment. Learn more about virtual environments.
ChatGPT - Ask “What Python package should I use for [task]?” - Great for recommendations and comparisons
Google “Python package for [task]”
ChatGPT is excellent for finding packages. Try asking: “What’s the best Python package for reading Excel files?” or “Compare pandas vs polars for data analysis.” It can explain which package to use and why.
# Wrong - package not installed or venv not activatedimport pandas # ModuleNotFoundError# Right - install first# Run: pip install pandasimport pandas
Name conflicts
Copy
# Wrong - overwrites built-inimport datetimedatetime = "2024-01-01" # Now module is gone!# Right - use different namesimport datetimedate_string = "2024-01-01"