Python Basics
Comparison and Logical Operators
| Operator | Meaning |
|---|---|
== | Equal |
!= | Not equal |
> < >= <= | Greater / less than |
and | Both true |
or | At least one true |
not | Reverse |
in | Is inside a collection |
is | Is the same object (use for None) |
age = 20
has_id = True
print(age >= 18 and has_id) # True
print(age < 13 or has_id) # True
print(not has_id) # False
print("a" in "apple") # True
print(10 < age < 30) # True (chained comparison)