Skip to content

Concepts: Numbers and maths

Short essays on the ideas behind numbers in Python. Read these once and keep coming back to them when a calculation surprises you or you're deciding how to store a quantity.

Essays in this section

  • How floating point works — what a float actually is: IEEE 754 double precision, why a tidy decimal like 0.1 can't be stored exactly, where the 53 bits of precision go, and what all of that means for the code you write.
  • Choosing a numeric type — a first-principles guide to picking between int, float, Decimal, and Fraction: exactness versus speed and range, and the kinds of quantity each one is built for.