Logic Operators

13. Logic Operators

Logical operators allow your program to combine conditions or reverse them.

OperatorMeaningExample
andBoth conditions must be truex > 5 and x < 10
orAt least one condition must be truex < 5 or x > 10
notReverses the resultnot 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:

  • and requires all conditions to be true.
  • or requires at least one condition to be true.
  • not reverses True and False.