Arithmetic
+, -, *, / (always a float), // (floor division), % (remainder), ** (power).
Assignment
=, +=, -=, *=, /=, //=, %=, **=. Python has no ++ or --; use x += 1.
Comparison (result is True/False)
==, !=, >, <, >=, <=. You can chain them: 18 <= age < 60.
Logical
and, or, not. They short-circuit: in a and b, b is not checked if a is False.
Membership
in, not in — "a" in "cat", 3 in [1, 2, 3], "key" in my_dict.
Identity
is, is not — the same object (use for None). == checks equal values.
Bitwise
&, |, ^, ~, <<, >> — work on binary bits.
The walrus operator
:= assigns inside an expression: if (n := len(items)) > 5:
Precedence
** → * / // % → + - → comparisons → not → and → or. Use brackets to make intent clear.
Example
a, b = 17, 5
print(a + b, a - b, a * b, a / b, a // b, a % b, a ** 2)
age = 25
print(18 <= age < 60) # chained comparison
has_ticket, is_vip = True, False
print(has_ticket and not is_vip)
fruits = ["apple", "mango"]
print("mango" in fruits, "kiwi" not in fruits)
x = [1, 2]
y = [1, 2]
print(x == y, x is y) # equal values, different objects
count = 0
count += 5
print(count)
if (n := len(fruits)) >= 2:
print(f"{n} fruits")
Output: 22 12 85 3.4 3 2 289, True, True, True True, True False, 5, 2 fruits