Python not Keyword
A logical operator that returns True
if the statement is False
,
returns False
if the statement is True
.
Example
Python
Copy Code
success = False if not success: print('Sadly, we did not succeed') # but what if we turn things around? success = not success # success will now be 'not False' which is True if (success): print('Yes, we succeeded!')
Output
Sadly, we did not succeed Yes, we succeeded!
Notes
You can use the not operator in other interesting ways, for example:
Python
Copy Code
print(not 1 < 2) print(not 1 in [2, 3, 4])
Output
False True