Python Basics — Modules & Packages
less than 1 minute read
Modules & Packages
As your programs grow, you’ll need to organize code into reusable pieces. Python’s module and package system makes this easy — and gives you access to thousands of pre-built libraries.
What You’ll Learn
Quick Preview
# Using a built-in module
import math
print(math.sqrt(144)) # 12.0
# Using a specific function
from datetime import datetime
print(datetime.now().strftime("%Y-%m-%d")) # 2025-03-03
# Using a third-party package (install with pip)
# pip install requests
import requests
response = requests.get("https://api.github.com")
print(response.status_code) # 200
Module vs Package
| Concept |
What It Is |
Example |
| Module |
A single .py file |
math.py, helpers.py |
| Package |
A directory of modules with __init__.py |
mypackage/ |
| Library |
A collection of packages |
requests, numpy |
| Framework |
A library with a structure/pattern |
Django, Flask |
Start Learning: Importing Modules →