Python not Keyword

The not keyword in Python is used when we need to inverse the boolean value of evaluated expression. That is, the not keyword returns True, if the expression evaluates to be False, otherwise returns False, if the expression evaluates to be True. For example:

print(not True)
print(not False)

The output is:


Python not Keyword Truth Table

The truth table of not keyword in Python, is:

X not X
True False
False True

Python not Keyword Example

Here is an example of not keyword in Python:

print("Enter the Two Number: ", end="")
numOne = int(input())
numTwo = int(input())

x = numOne>numTwo
if not x:
    print("\nThe value", numOne, "is greater than", numTwo)
    print("\nThe value", numTwo, "is greater than", numOne)

print("\n\n\n@April Fool")

The snapshot given below shows the sample run of above program, with user input 10 and 30 as first and second numbers:

python not keyword

The not keyword in above program, reversed the result or output.

Python Online Test

« Previous Tutorial Next Tutorial »

© Copyright 2021. All Rights Reserved.