Comparison operators
Conditionals compare values with these operators:
| Operator | Means |
|---|---|
== | equal to |
!= | not equal |
< > | less / greater than |
<= >= | less/equal / greater/equal |
age = 16
if age >= 16:
print("Can drive (in many places)")
Note == (compare) is not the same as = (assign). Mixing them is a classic bug.
Truth tables and short-circuiting
and and or short-circuit: evaluation stops as soon as the result is known.
A and B -> if A is False, B is not checked
A or B -> if A is True, B is not checked
This is useful for safe checks:
if user and user.is_admin:
delete_everything()
user.is_admin only runs if user exists. That prevents crashes on empty input.