AND Operator

The full text of this chapter, to read or revisit. To practise, do the exercises.

β–Ά Do the exercises

Exercise 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