Python Logical NOT - not keyword


Python NOT

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

Syntax of 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

Examples

1. Python NOT with boolean values

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)

Output

not True is: False
not False is: True

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)

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.