# Double negation and bool()
x = 42print(notnot x) # Same as bool(x)print(bool(x)) # Clearer way# not vs !=
items = [1, 2, 3]
# These are different:print(not items == []) # not (items == []) = not False = Trueprint(items != []) # True (preferred)# De Morgan's laws
a, b = True, Falseprint(f"not (a or b) = {not (a or b)}")
print(f"(not a) and (not b) = {(not a) and (not b)}")
print(f"not (a and b) = {not (a and b)}")
print(f"(not a) or (not b) = {(not a) or (not b)}")
Output
Click "Run" to execute your code
'not' always returns a boolean. Use it for readability, but prefer 'is not', 'not in', and '!=' over 'not ... is', 'not ... in', and 'not ... =='.
Challenge
Try modifying the code above to explore different behaviors. Can you extend the example to handle a new use case?