MODULES & PACKAGES · 6 MIN
Modules & Packages
Modules are Python files you import to reuse code; packages are folders of modules.
PYRA explains
- import math gives math.sqrt(); from math import sqrt imports just one name.
- The standard library ships with Python: random, datetime, json, collections and more.
- Third-party packages are installed with pip, e.g. pip install requests.
Real world: Borrowing a ready-made toolkit instead of forging every tool yourself.
Code
import math
from collections import Counter
print(math.sqrt(49), math.pi > 3)
print(Counter("banana").most_common(1))Output ›
7.0 True
[('a', 3)]Try it in the online compiler →Checkpoint quiz
Which installs a third-party package?