Editor settings

General settings

Save settings

Learn to program with Python

Chain booleans with the or keyword #

The or keyword is different from the and that or returns True if any conditions in the expression evaluate to True. For the expression to be False, all conditions must be False.

For example:

x = 5
y = 10
z = 15

result = x < y or y < z # True or True
print(result) # Output: True

result_2 = x < y or y == z # True or False
print(result_2) # Output: True

result_3 = x == y or y == z # False or False
print(result_3) # Output: False

In the above example, the variable result and result_2 are both True, since at least one of the conditions are True. However, the variable result_3 is False because all of the conditions are False.


Exercise #

Use the keyword or to set the variables' values

Tests #

  • Variable true should be True
  • Variable false should be False
  • Use the keyword or to set the variable true
  • Use the keyword or to set the variable false
Output will be displayed here