Getting Started With Python's not Operator
Let’s take a look at how the
not operator works in Python. Python uses
not to implement the negation operation. Negation is a unary operation, meaning it takes just one expression as an operant. In Python, that operand could be a Boolean expression or another type of Python object.
If the operand it’s applied to evaluates to
True, then the result of the
not operation is
False. Similarly, if the operand evaluates to
False, then the result of the
not operation applied to it is
Many times, the function of Boolean operators is described in a truth table. Here is the one for
not. It basically says that if the operand is
not operand is
False. And if the operand is
False, then the
not of it is
Where might you use the
not operator? One case is when you’re looking for a condition that isn’t met during some
while statement, negating or inverting the value of a Boolean expression, checking to see if an item is not in a given collection of things, and in sometimes checking for object identity.
01:22 And this course will show you examples of all of these.
Become a Member to join the conversation.