Operators combine values into expressions. Python's set is small and readable — most of them do exactly what you'd expect.
Arithmetic
7 + 2 # 9 addition7 - 2 # 5 subtraction7 * 2 # 14 multiplication7 / 2 # 3.5 division (always a float)7 // 2 # 3 floor division (drops the remainder)7 % 2 # 1 modulo (the remainder)7 ** 2 # 49 exponent (7 squared)
Comparison
5 == 5 # True equal5 != 3 # True not equal5 > 3 # True5 <= 5 # True# Python allows chaining:1 < x < 10 # True if x is between 1 and 10
Logical
(age >= 18) and (has_id) # both must be True(is_weekend) or (is_holiday) # either is enoughnot is_active # inverts the boolean
Assignment & membership
x = 10x += 3 # x = x + 3 → 13 (also -=, *=, /=, //=, %=, **=)"a" in "cat" # True membership3 in [1, 2, 3] # True"z" not in "cat" # True
Key takeaways
- 01Arithmetic: + - * / // % ** — note / is float division, // floors, % is remainder.
- 02Comparisons (==, !=, <, >, <=, >=) return booleans and can be chained (1 < x < 10).
- 03Logical operators and/or/not combine or invert booleans.
- 04Augmented assignment (+=, -=…) updates in place; in / not in test membership.
