Python NOT Operator

In Python, Logical NOT Operator takes a single boolean value or expression as operand and returns the result of its logical NOT operation. The logical AND operator returns True if operand is False, or returns False if the operand is True.

Syntax

The syntax to find the logical NOT of a boolean value x using logical NOT Operator is

not x

The above expression returns a boolean value.

ADVERTISEMENT

Examples

1. Logical NOT operation of a boolean value

In the following program, we take a boolean value in x and find the result of its logical NOT operation.

main.py

x = True
result = not x
print(result)
Try Online

Output

False

Now, we shall take False in x, and find the result of logical NOT operation.

main.py

x = False
result = not x
print(result)
Try Online

Output

True

2. NOT Operator with boolean expression

In the following program, we take an integer value in x, and check if the value in x is not a negative number.

The condition to check if x is a negative number is x < 0. Therefore, the condition to check if x is not a negative number is not (x < 0).

main.py

x = 14

if not (x < 0) :
    print('x is not negative.')
Try Online

Output

x is not negative.

Conclusion

In this Python Tutorial, we learned about Logical NOT Operator, its syntax, and usage, with examples.