Python · Boolean in Depth
AND Operator
The full text of this chapter, to read or revisit. To practise, do the exercises.
▶ Do the exercisesExercise 1 — AND Operator
The
and
operator is a logical operator that returns
True
if both sides are
True
. Otherwise, it returns
False
.
Here is a truth table for the
and
operator with 2 variables (
A and B = ?
). It shows all possible combinations of
True
and
False
.
Exercise 2 — AND Operator
We can also try to display the truth table with code !
print("False and False =", False and False)
print("True and False =", True and False)
print("False and True =", False and True)
print("True and True =", True and True)
Remember,
and
returns
True
only if both sides are
True
.
Exercise 3 — Did you get AND?
Match each formula of the left with its result on the right.
Items to match
• True and True
• True and False
• False and True
• False and False
Definitions
• True
• False
• False
• False
Exercise 4 — AND Operator Quiz
What will be the result of
True and False
?
Options
• ```False```
• ```True```
• ```Error```
• ```None```
Hint : With AND operator, both sides must be True to get True.
Exercise 5 — Match AND Results
Match each AND 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)
Items to match
• True and True and True
• True and False and True
• False and False and False
• True and True and False
Definitions
• True
• False
• False
• False
Back to the course