Arithmetic Operators
Seven symbols do all the math in Python. You've already used several — now let's make each one precise, including the three that surprise beginners.
The full set
print(10 + 3) # 13 addition
print(10 - 3) # 7 subtraction
print(10 * 3) # 30 multiplication
print(10 / 3) # 3.3333333333333335 true division
print(10 // 3) # 3 floor division
print(10 % 3) # 1 modulo (remainder)
print(10 ** 3) # 1000 exponentThe division family — know all three
Python is unusual in having three division-related operators, and mixing them up is the classic beginner bug:
| Operator | Name | What it gives | Example |
|---|---|---|---|
/ | true division | Always a float, decimals included | 10 / 3 → 3.3333... |
// | floor division | Rounds down to a whole number | 10 // 3 → 3 |
% | modulo | Just the remainder | 10 % 3 → 1 |
Watch // with negatives — "floor" means round *down*, not "cut off":
print(7 // 2) # 3
print(-7 // 2) # -4 ← floors DOWN, not toward zero
print(int(-7 / 2)) # -3 ← int() truncates toward zeroModulo — the secret weapon
% looks obscure until you see its greatest hits:
# Even or odd?
number = 17
print(number % 2 == 0) # False → odd
# Last digit of a number
print(4826 % 10) # 6
# Every Nth item
for minute in range(1, 61):
if minute % 15 == 0:
print(f"Minute {minute}: take a break!")
# Wrapping around (a clock!)
print((10 + 5) % 12) # 3 → 10 o'clock + 5 hours = 3 o'clockEven/odd checks, cycles, digits, schedules — % is everywhere once you can see it.
Exponent: **
print(2 ** 10) # 1024
print(9 ** 0.5) # 3.0 ← square root via half-power!
print(2 ** -2) # 0.25 ← negative powers tooOrder of operations
Python follows standard math precedence — and parentheses always win:
print(2 + 3 * 4) # 14
print((2 + 3) * 4) # 20
print(2 ** 3 ** 2) # 512 — powers chain RIGHT to left: 2**(3**2)That last one is exotic; the practical rule is simpler: when unclear, parenthesize.
Working with floats — the honest truth
print(0.1 + 0.2) # 0.30000000000000004 ← what?!
print(0.1 + 0.2 == 0.3) # FalseComputers store decimals in binary, and some decimals can't be represented exactly — a tiny error creeps in. This is not a Python bug; it's how all languages work. Practical responses:
print(round(0.1 + 0.2, 2)) # 0.3 — round for display
# For money: work in paise/cents as ints (1850 paise, not 18.50 rupees)Common Errors & Fixes
if divisor != 0:."5" * 3 is fine — it repeats!). Convert to numbers first./ always floats; use // when you want whole numbers.✅ Checkpoint
9 % 4 = ? *(1)*2 ** 3 ** 2 = ? *(512 — powers chain right-to-left: 2**(9))*0.1 + 0.2 == 0.3? *(False — float precision; use round())*Next: comparison operators — how numbers turn into True and False.