Lesson 24 of 40Article14 min
Statistics & Math Module Reference
statistics.mean, median, mode, stdev work on Python lists — no NumPy required.
Statistics module
statistics.mean, median, mode, stdev work on Python lists — no NumPy required.
Good for quick summaries in scripts and homework.
Real-life example: statistics.mean is the class average — one number summarizing everyone's test.
Basic stats
import statistics
scores = [80, 85, 90, 92, 88]
print(statistics.mean(scores))
print(statistics.median(scores))Math module (reference highlights)
math.sqrt, pow, ceil, floor, factorial, gcd, sin, cos, log, pi, e.
For vector math use NumPy; math is for scalar operations.
Real-life example: math.factorial is counting arrangements — how many ways to order 5 books on a shelf.
Math highlights
import math
print(math.sqrt(49), math.factorial(5))
print(math.gcd(48, 18))
print(round(math.sin(math.pi / 2), 2))