Python not Keyword

Python provides the not keyword in order to calculate the reverse of the boolean value. Boolean values are True and False. So if the not keyword is used for the True value the result is False. If the not keyword is used for the False value the result is True. In this tutorial, we examine different usages of the not keyword.

not Keyword

The not keyword has the following calculation table when used with the True and False boolean values.

Boolean ValueResult
TrueFalse
FalseTrue

not Keyword Examples

The not keyword can be used with the boolean variables and values. The not keyword is used before the boolean variable or value like below.

a = True

b = False

print(not a)

print(not b)

print(not True)

print(not False)
False
True
False
True

Using not Keyword with If Statement

One of the most popular uses for the not keyword is using it with the if statements. The if statements require boolean values which can be True or False and executes according to these boolean values.

a = True

b = False

if(not a):
   print("a is not True")

if(not b):
   print("b is not False")

Leave a Comment