Using Python's and Operator With Boolean Expressions
00:00
Let’s take a look at how and
is used with Boolean expressions. Remember a Boolean expression is an expression that evaluates to True
or False
.
00:13 The most common of these are when you do comparisons, like seeing if two expressions have the same value, seeing if one number is larger than another or smaller than, and even non-numeric values can be compared.
00:33
Each of these expressions evaluated to either True
or False
. And these are the most common expressions to use with the and
operator.
00:43
We can connect two expressions that are true with and
00:50
and see that the result is True
. If the first expression is false and the second is true, you can see that it is False
. If the first is true and the second is false, the whole thing is False
.
01:09
And if both expressions are false, the and
of them is False
as well. You can use multiple and
operators to connect more than two expressions.
01:22
In this case, the overall expression will evaluate to True
only when each of the individual operand expressions are true.
01:32
If at least one of the operands is false, then the end of them will evaluate to False
.
01:43
Next, we’ll look at how you can improve the performance of your program by taking advantage of one of the ways Python implements its and
operation.
Become a Member to join the conversation.