IntermediateLesson 10 of 12
Modules, Packages & pip – Python
Using the standard library and installing packages.
With import you use ready-made code. The standard library is huge: math, random, datetime, json, collections, re …
import math, random, json
from datetime import date
print(math.sqrt(16), math.pi)
print(random.choice(["red", "green", "blue"]))
print(json.dumps({"a": 1, "b": [1, 2]}))
print(date.today().year)You install third-party packages with pip (in the terminal, not in Python code):
pip install requests
pip freeze > requirements.txt
pip install -r requirements.txtTipYour own modules are simply
.py files: import meinmodul loads meinmodul.py from the same folder.