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 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.
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.
#not True a = True c = not a print('not',a,'is:',c) #not False a = False c = not a print('not',a,'is:',c)
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.
#not True a = 5 c = not a print('not',a,'is:',c) #not False a = 0 c = not a print('not',a,'is:',c)
not 5 is: False not 0 is: True
In this tutorial of Python Examples, we learned about Python not logical operator with the help of well detailed examples.