Skip to content
UPEEC

Numbers in Python

int, float and complex — Python integers never overflow; floats follow IEEE 754.

Beginner
Comments 0
  • int — arbitrary precision: 2 ** 100 works exactly.
  • float — 64-bit IEEE 754: 0.1 + 0.2 == 0.30000000000000004. Compare floats with math.isclose().
  • complex — handy for AC circuit maths: z = 3 + 4j, abs(z) == 5.0.

Useful operators: // (floor division), % (modulo), ** (power). Use the decimal module when you need exact decimal arithmetic (e.g. money).

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.