Python Logical NOT Operator

Python NOT

To perform logical NOT operation in Python, you can use not keyword prior to the boolean value or boolean operand.

Syntax – not keyword

The syntax to use not operator is:

not operand

not operator takes only one operand. not operator returns True, if the operand is False and returns False if the operand is True.

Truth Table – NOT Operator

Following is the truth table of not operator with boolean values.

OperandReturn Value
TrueFalse
FalseTrue

Example 1: Python NOT

In the following example, we will try to use not keyword to perform logical not operation for True and False boolean values.

Python Program

#not True
a = True
c = not a
print('not',a,'is:',c)

#not False
a = False
c = not a
print('not',a,'is:',c)
Run this program

Output

not True is: False
not False is: True

Example 2: NOT Operator with non-boolean operands

You can use non-zero values instead of True and zero for False.

Python Program

#not True
a = 5
c = not a
print('not',a,'is:',c)

#not False
a = 0
c = not a
print('not',a,'is:',c)
Run this program

Output

not 5 is: False
not 0 is: True

Summary

In this tutorial of Python Examples, we learned about Python not logical operator with the help of well detailed examples.