Python - Logical Operators

python logo pixel art

Python has logical operators to combine or compare boolean values.



The 'and' and 'or'

python logical operators table

The 'not'

The 'not' logical operator just inverts the boolean.

print(not False) # True
print(not True) # False 

Examples

age0 = 69
age1 = 169
print(age0 > 0 and age0 < 100) # True
print(age1 > 0 and age1 < 100) # False
age0 = 69
age1 = 169
print(age0 <= 0 or age0 >= 100) # False
print(age1 <= 0 or age1 >= 100) # True
isPython = True
isJavaScript = False

print(not isPython) # False
print(not isJavaScript) # True