devnotes.

Numbers and Arithmetic in Python

Python's numeric types and operators have a few behaviors that differ meaningfully from C-family languages.

print(7 / 2)     # 3.5  — / is ALWAYS true division, returns a float
print(7 // 2)    # 3    — // is floor division, for integer-style division
print(7 % 2)     # 1    — modulo, same as most languages
print(2 ** 10)   # 1024 — ** is exponentiation, no separate pow() needed

big = 99999999999999999999999999 * 2   # ints have arbitrary precision — no overflow
print(big)

x = 5
x += 1            # 6 — Python has no ++ or -- operators, use += / -=

Unlike C or Java, / in Python always performs true (floating-point) division, even between two integers — 7 / 2 is 3.5, never truncated. // (floor division) is the explicit operator for integer-style division, rounding down (toward negative infinity, not toward zero — -7 // 2 is -4, not -3).

Python integers have arbitrary precision — they grow as large as memory allows, with no fixed bit-width and no silent overflow the way C's int can wrap around; this is one of the more pleasant differences for anyone coming from a lower-level language.

Python deliberately has no ++/-- increment/decrement operators (a design choice to avoid the C-style pitfalls and ambiguity they introduce) — use x += 1 and x -= 1 instead. The decimal module (Decimal) is available for exact decimal arithmetic when float's binary floating-point imprecision would matter, such as in financial calculations.

Numbers and Arithmetic in Python | DevNotes