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 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)
Run Code Copy

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)
Run Code Copy

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.

Related Tutorials

Code copied to clipboard successfully 👍