Learn: Numbers and maths¶
Four notebooks, in order. Each is self-contained, but they build on each other — the first two cover the built-in types and their sharpest edge, the last two add the exact types and the standard-library toolkit.
Notebooks in this section¶
- Numeric types —
int,float, andcomplex; numeric literals (underscores, hex/binary/scientific); the arithmetic operators including//,%,divmod, and**; whyintnever overflows; and how Python mixes types in an expression. - Floating point — why
0.1 + 0.2isn't0.3, whatfloatcan and can't represent, comparing floats withmath.isclose, the surprise inround, and the special valuesinfandnan. - Decimal and Fraction — exact decimal arithmetic with
Decimal(and the one rule that makes it work), rounding to the penny withquantize, exact rationals withFraction, and when each earns its keep. - Maths, statistics, and random — the
mathmodule (roots, logs, trig, combinatorics, constants), summary statistics withstatistics, and generating random numbers withrandom— plus when to reach forsecretsinstead.
After these, the Recipes cover task-focused applications and the Reference has quick lookups for math, number formatting, and the types and operators.