Logic Operators
13. Logic Operators
Logical operators allow your program to combine conditions or reverse them.
| Operator | Meaning | Example |
|---|---|---|
and | Both conditions must be true | x > 5 and x < 10 |
or | At least one condition must be true | x < 5 or x > 10 |
not | Reverses the result | not active |
Example:
temperature = 25
button = True
if temperature > 20 and button:
print("Start the robot")
if temperature < 10 or not button:
print("Stop the robot")Remember:
andrequires all conditions to be true.orrequires at least one condition to be true.notreverses True and False.
