Using Python's and Operator With Boolean Expressions
Let’s take a look at how
and is used with Boolean expressions. Remember a Boolean expression is an expression that evaluates to
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.
Each of these expressions evaluated to either
False. And these are the most common expressions to use with the
We can connect two expressions that are true with
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
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.
In this case, the overall expression will evaluate to
True only when each of the individual operand expressions are true.
If at least one of the operands is false, then the end of them will evaluate to
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
Become a Member to join the conversation.