The not Operator Returning the Opposite
In this lesson, we will take a closer look at the previously introduced not
operator.
The not
operator returns the opposite of a Boolean value.
It is primarily used in conjunction with conditional statements to handle cases where a certain condition is the opposite.
Using the not Operator
The not
operator returns False
if the value on its right is True
, and True
if the value is False
.
Using the not Operator
is_logged_in = False # Prints True, the opposite of False print("not is_logged_in:", not is_logged_in) if not is_logged_in: print("Login is required.")
Mission
0 / 1
The not
operator returns the opposite of the boolean value on its left.
O
X
Guidelines
AI Tutor
Publish
Design
Upload
Notes
Favorites
Help
Code Editor
Run
Generate
Execution Result