Last updated
Python Operators
Definition: Operators are the symbols that perform actions on values — maths, comparisons, and logic.
Arithmetic operators
Do maths (covered in the Numbers lesson): + - * / // % **
Example 1 — comparison operators
Compare two values; the result is a boolean:
print(5 == 5) # True print(5 != 3) # True print(7 >= 7) # True print(2 < 1) # False
Example 2 — logical operators
and, or, and not combine conditions:
age = 25 print(age > 18 and age < 65) # True (both true) print(age < 13 or age > 100) # False (neither true) print(not age == 25) # False (flips True)
Example 3 — assignment shortcuts
These update a variable in place:
x = 10 x += 5 # x = x + 5 -> 15 x -= 3 # -> 12 x *= 2 # -> 24 print(x)
Example 4 — the "in" operator
in checks whether something is inside a collection or string:
print("a" in "cat")
print(3 in [1, 2, 3])
💡 Tip: += and friends appear constantly in real code — especially for counters and running totals.
Try it Yourself
Output
Ad · responsive