Skip to content

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

  1. Numeric typesint, float, and complex; numeric literals (underscores, hex/binary/scientific); the arithmetic operators including //, %, divmod, and **; why int never overflows; and how Python mixes types in an expression.
  2. Floating point — why 0.1 + 0.2 isn't 0.3, what float can and can't represent, comparing floats with math.isclose, the surprise in round, and the special values inf and nan.
  3. Decimal and Fraction — exact decimal arithmetic with Decimal (and the one rule that makes it work), rounding to the penny with quantize, exact rationals with Fraction, and when each earns its keep.
  4. Maths, statistics, and random — the math module (roots, logs, trig, combinatorics, constants), summary statistics with statistics, and generating random numbers with random — plus when to reach for secrets instead.

After these, the Recipes cover task-focused applications and the Reference has quick lookups for math, number formatting, and the types and operators.