Modules & Packages
📦 Modules & Packages
pip, and keeping each project's dependencies isolated with a virtual environment.
📥 Importing Modules
The star-import form dumps every public name from a module directly into your current namespace. It's convenient in a quick throwaway script, but in real code it makes it unclear where a given name actually came from, and it can silently overwrite (shadow) names you've already defined — including built-ins. Stick to import module or from module import specific_name instead.
📚 The Standard Library
Python ships with a large "batteries included" standard library — modules available immediately with no installation step:
📦 pip and Third-Party Packages
pip is Python's package installer, used for code outside the standard library:
A project's dependencies are typically tracked in a requirements.txt file — one package (and optionally a version) per line — so anyone else can recreate the exact same set with pip install -r requirements.txt.
🧪 Virtual Environments (venv)
Installing packages globally on your machine causes real problems the moment two projects need different, conflicting versions of the same package. A virtual environment gives each project its own isolated set of installed packages:
Creating a fresh venv for every new Python project is standard practice, not an optional extra — it's the direct equivalent of Node's per-project node_modules folder, keeping each project's dependencies self-contained and reproducible on another machine.
Dependency Management: Go vs Kotlin vs Python
| Language | Approach |
|---|---|
| Go | go.mod/go.sum declare and lock dependency versions per-project automatically — isolation is built into the tooling, no separate "activate an environment" step. |
| Kotlin | Gradle (or Maven) resolves dependencies declared in build.gradle.kts, scoped per-project by default — also no manual activation step. |
| Python | pip installs packages, but isolation isn't automatic — a venv has to be deliberately created and activated per project, or packages land in one shared global location. |
This is a genuine rough edge coming from Go or Kotlin — both of those ecosystems bake project-level isolation into the build tool itself, while Python's isolation is a separate, opt-in step you have to remember to take.
import
import x, import x as y, from x import y — avoid from x import *.
Standard library
math, random, datetime, os, and many more — no install needed.
pip
Installs third-party packages; dependencies tracked in requirements.txt.
venv
An isolated, per-project set of installed packages — create and activate before installing anything.
💻 Coding Challenges
Challenge 1: Random Dice Roller
Using the random module, write a function roll_dice() that returns a random integer between 1 and 6 (inclusive), then call it and print the result.
Goal: Practice importing and using a standard library module.
Challenge 2: Days Until a Date
Using the datetime module, calculate and print how many days remain until January 1st of next year, starting from today's date.
Goal: Practice working with the datetime module and date arithmetic.
Challenge 3: Write a requirements.txt
Write out (as plain text, no code needed to run) a requirements.txt file listing three made-up third-party packages your project depends on, each pinned to a specific version using the == syntax.
Goal: Get familiar with the requirements.txt format itself, since you'll be reading and writing these in almost every real Python project.
🎓 Course Complete!
That's all 9 chapters of Python Fundamentals — installation, variables, control flow, loops, strings, lists/tuples/sets, dictionaries, functions, and modules/packages. Next up: Python Intermediate (py2), starting with Object-Oriented Programming.