Seven Arithmetic Operators, Two Worth Dwelling On
17 + 5 # 22
17 - 5 # 12
17 * 5 # 85
17 / 5 # 3.4 true division — always a float
17 // 5 # 3 floor division — the whole part
17 % 5 # 2 modulo — the remainder
17 ** 2 # 289 power
// and % are the two most people skip, and they
are the two that earn their keep. Together they answer one question:
how many whole ones fit, and what is left over?
Unit conversion
seconds // 60 whole minutes, seconds % 60 the leftover seconds.
Grouping
items // per_page full pages, items % per_page the last partial one.
Divisibility
n % 2 == 0 asks whether n is even. Any remainder of zero means it divides cleanly.
Cycling
index % length turns a rising counter into a repeating loop through positions.
Everyday example, splitting the bill
47 sweets between 5 children. 47 / 5 is 9.4, which is a
true answer and completely useless — nobody hands out four tenths of a
sweet. 47 // 5 is 9 each, and 47 % 5 is the 2
left in the bag. Those are the two numbers a person actually needs.
Quick check
You have 100 items and show 8 per page. Which expression gives the number of items on the final, partly-filled page?