Python - Logical Operators
Python has logical operators to combine or compare boolean values.
- and - AND
- or - OR
- not - NOT
The 'and' and 'or'
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