Mixing Boolean Expressions With Objects
00:00
In this lesson, you’ll learn that you can actually mix Boolean expressions with objects using and
. And once you understand how Python implements and
, you’ll see that it’s not much different. x
and y
will evaluate to x
if x
is false, and it doesn’t matter if x
is a Boolean expression or an object. Likewise, if x
is true, the result is y
, and it too can be a Boolean expression or an object.
00:30
So let’s look at some examples. Here, the first expression is true, so the result will be second expression, 2
. Switching them around, 2
is true, so the result will be 2 < 4
, which evaluates to True
.
00:56
Here, again, the left part is true, so the result will be the right part, the empty list. But here, an empty list is False
, so that will be the result.
01:14
5
isn’t greater than 10
. That evaluates to False
, so False
will be the result.
01:25
And here, an empty dictionary is considered False
, so that’s the result.
01:34
Once again, the left part evaluates to False
, so that’s the result. But this way, 4
is True
, so the result will be the value of 5 > 10
.
01:49
Again, same rules: first operand False
, that value is returned. First operand True
, the second operand’s value is returned. Next, you see how and
interacts with other operations in Python.
Become a Member to join the conversation.