The arithmetic seven (+ − * / // % **), comparisons that return True/False, and the precedence ladder that decides which operation goes first.
01
Learning objectives
Use all seven arithmetic operators and predict each result, including // and % on negatives-free examples.
Explain the difference between / (true division, float) and // (floor division, int).
Apply the precedence ladder: ** first, then * / // %, then + −, left to right.
Use comparison operators (== != > < >= <=) and state that they produce bool values.
Combine conditions with and, or, not and use % to test even/odd and divisibility.
02
Lesson notes
An expression is a combination of values, variables and operators that Python evaluates down to a single value. The arithmetic set has seven members. The familiar four: + addition, - subtraction, * multiplication, / division. Then three that make board papers interesting: // floor division (divide, drop the fraction), % modulo (the remainder after division), and ** exponent (power). One line covers the most-tested fact of the chapter: 17 / 5 is 3.4 (always a float), 17 // 5 is 3 (floored), and 17 % 5 is 2 (because 17 = 5 × 3 + 2).
The modulo operator % deserves special affection because it answers real questions directly. Is a number even? n % 2 == 0. Does 7 divide 91? 91 % 7 == 0. What digit does a number end in? n % 10. Extract the last two digits of a year? year % 100. Whenever a problem talks about remainders, cycles, or every-kth-item, % is the tool. Note also that % and // form a pair: for any division, (a // b) * b + a % b rebuilds a exactly — a neat check examiners expect you to know.
Precedence decides which operator binds first when an expression mixes several. The ladder, highest first: brackets (), then **, then * / // %, then + -, all evaluated left-to-right within the same rung. So 4 + 3 * 2 ** 2 becomes 4 + 3 × 4 = 16, NOT (4+3)×4 = 28. The classic safety net is brackets: when in doubt, add parentheses to make your intention the interpreter's instruction — and in traces, write one operation per line to show the order you used.
Comparison operators ask questions instead of computing quantities: == equal to (TWO equals signs — one means assignment!), != not equal, >, <, >=, <=. Every comparison returns a bool: 5 > 3 is True, marks == 88 is True only when marks holds exactly 88. The single most expensive typo in beginner Python is writing if marks = 88: — assignment inside a condition is a SyntaxError, precisely because the two jobs must never blur.
Comparisons chain and combine. Python allows the mathematical range form directly: 0 <= marks <= 100 is legal and reads beautifully. For combining independent questions, the logical operatorsand (both sides must be True), or (at least one side True) and not (flips True/False) build any compound condition you need: percentage >= 80 and attendance >= 75 gates an A grade on both requirements. Chapter 4 turns these into decisions; for now, practise evaluating them to a single True or False on paper.
03
Worked code examples
The division family on one number pair
/ gives the exact quotient 3.4 as a float; // drops the fraction to 3; % keeps the remainder 2. The final line shows the pair identity: 3 × 5 + 2 = 17.
a, b = 17, 5
print(a / b) # true division
print(a // b) # floor division
print(a % b) # remainder
print((a // b) * b + a % b) # rebuilds a
Output
3.4
3
2
17
Precedence, step by step
2 ** 2 first (4), then 3 * 4 (12), then 4 + 12 = 16. Brackets force (4+3) first, giving 28. Even ** chains go right-to-left: 2 ** (3 ** 2) = 2 ** 9 = 512.