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.
The syntax to find the logical NOT of a boolean value
x using logical NOT Operator is
The above expression returns a boolean value.
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.
x = True result = not x print(result)Try Online
Now, we shall take False in
x, and find the result of logical NOT operation.
x = False result = not x print(result)Try Online
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).
x = 14 if not (x < 0) : print('x is not negative.')Try Online
x is not negative.
In this Python Tutorial, we learned about Logical NOT Operator, its syntax, and usage, with examples.