Standard Library Tour
beginner12 min readLesson 38 of 169
random, datetime, statistics โ borrowed power with reproducible results.
The standard library is the toolbox that ships with Python. Four workhorses:
random โ simulations and games
import random
roll = random.randint(1, 6) # 1..6 inclusive
pick = random.choice(["a", "b", "c"])
random.seed(42) # reproducible "randomness"
seed pins the generator: same seed, same sequence โ essential for tests and
debugging.
datetime โ timestamps and durations
from datetime import date
today = date(2026, 9, 13)
print(today.year, today.month) # 2026 9
print(date(2026, 9, 13) - date(2026, 1, 1)) # 255 days, 0:00:00
statistics โ one-line averages
import statistics
statistics.mean([2, 4, 9]) # 5
statistics.median([1, 9, 5]) # 5
The lesson here is bigger than any one module: before writing a helper, suspect the standard library already has it.