Getting Started With Python's and Operator
In this lesson, you’ll see the basic definition of the
00:06 As the word suggests, an operator acts on one or more items, which are called operands. For example, if you add two numbers together, those two numbers are called the operands.
and, the operands can be two Boolean expressions, two other types of objects—which you’ll see in future lessons—or even a combination of both.
Since it takes two operands,
and is referred to as a binary operator.
This table, called a truth table, shows the behavior of the
and operator. Basically, if both operands evaluate to
True, then the
and of those expressions is
True. In all other cases, the result of the
and operation is
False. So if you’re taking the
and of two expressions,
exp2, if both are
and of them is
If the first one is
False and the second one is
False. In the next row,
And finally, in the last row,
True. I want you to make an observation about this table. Notice that if expression one is
and of both expressions is
It’s essentially the first expression, no matter what the second expression is. And in the second two rows, where the first expression is
True, then the result of the
and operation is whatever the expression two is.
01:56 The Python programming language and the programmers who use it take advantage of this operation when writing programs. And you’ll see that in future lessons as well.
But in the next lesson, you’ll see the most basic cases of using the
and operator in Python.
Become a Member to join the conversation.