Python's operators cover the same ground as most languages' — arithmetic, comparison, logic — with a few of Python's own choices worth flagging specifically.
| Operator | Meaning | Example |
|---|---|---|
| + | Addition | 5 + 2 → 7 |
| - | Subtraction | 5 - 2 → 3 |
| * | Multiplication | 5 * 2 → 10 |
| / | Division (always returns a float) | 5 / 2 → 2.5 |
| // | Floor division (rounds down to an int) | 5 // 2 → 2 |
| % | Modulus (remainder) | 5 % 2 → 1 |
| ** | Exponent | 5 ** 2 → 25 |
// is worth noting specifically: / always gives a float result, even when the numbers divide evenly, and // is how you deliberately get a whole number back instead.
Python uses + for both arithmetic and joining strings — there's no separate operator just for joining text. Python decides which one you mean from the types involved, which is exactly why mixing a string and a number with + raises an error rather than guessing (from the Data Types lesson):
greeting = "Hello, " + "world!"
print(greeting)
# name = "Age: " + 21 # TypeError — use an f-string instead (next lesson)== and is look similar but do different jobs. == compares value; is compares identity — whether two names point at the literal same object in memory:
a = [1, 2, 3]
b = [1, 2, 3]
c = a
print(a == b) # True — same values
print(a is b) # False — two different list objects, even though equal
print(a is c) # True — c points at the exact same object as aDefault to ==, use is for None checks
Use == for comparing values, which is what you want almost all of the time. is is specifically for checking identity, and its one genuinely common use is comparing against None: if value is None: is the idiomatic Python way to do it, not if value == None:.
Python spells these out as words rather than symbols — there's no &&, ||, or !:
age = 20
has_id = True
if age >= 18 and has_id:
print("Entry allowed.")
if not has_id:
print("ID required.")Every arithmetic operator has a compound form that updates a variable in place:
| Operator | Same as |
|---|---|
| x += 1 | x = x + 1 |
| x -= 1 | x = x - 1 |
| x *= 2 | x = x * 2 |
| x /= 2 | x = x / 2 |
| x //= 2 | x = x // 2 |
| x **= 2 | x = x ** 2 |
| x %= 2 | x = x % 2 |
You already saw count += 1 used as the standard way to increment a counter, since Python has no ++ — the same shortcut works for every operator in the table above.