Python · Boolean in Depth
OR Operator
The full text of this chapter, to read or revisit. To practise, do the exercises.
▶ Do the exercisesExercise 1 — OR Operator
The
or
operator is a logical operator that returns
True
if at least one side is
True
. Otherwise, it returns
False
.
Here is a truth table for the
or
operator with 2 variables (
A or B = ?
). It shows all possible combinations of
True
and
False
.
Exercise 2 — OR Operator
We can also try to display the truth table with code !
print("False or False =", False or False)
print("True or False =", True or False)
print("False or True =", False or True)
print("True or True =", True or True)
Remember,
or
returns
True
if at least one side is
True
.
Exercise 3 — Did you get OR?
Match each formula of the left with its result on the right.
Items to match
• True or True
• True or False
• False or True
• False or False
Definitions
• True
• True
• True
• False
Exercise 4 — OR Operator Quiz
What will be the result of
False or True
?
Options
• ```True```
• ```False```
• ```Error```
• ```None```
Hint : With OR operator, if at least one side is True, the result is True. Since one side is True, the result is True.
Exercise 5 — Match OR Results
Match each OR operation with its correct result.
In these type of operations, you're gonna want to read from left to right, evaluating what's within parentheses first if there are any, AND is evaluated before OR (similar to multiplication before addition).
Items to match
• True or True or True
• False or True or False
• False or False or False
• True or False or True
Definitions
• True
• True
• False
• True
Exercise 6 — Match Complex Boolean Results
Match each boolean operation with its correct result.
Remember: evaluate what's in parentheses first, then AND operations, and finally OR operations (reading left to right).
Items to match
• (True or False) and True
• False or (True and False)
• (False and True) or True
• True and (False or True)
• (True and False) or False
Definitions
• True
• False
• True
• True
• False
Back to the course