Custom Search

PYTHON: Logical Operators

 

Operator Description
and

'and' returns True if both statements are true

x = 5

print (x > 3 and x < 10)

This will return True because 5 is greater than 3 AND 5 is less than 10

or

'or' returns True if one of the statements is true

x = 5

print (x > 3 or x < 4)

This will return True because one of the conditions are true - 5 is greater than 3, but 5 is not less than 4.

not

'not' reverses the result, or returns False if the result is true.

x = 5

print(not(x > 3 and x < 10))

This will return False because although it is true, the 'not' has been used to reverse the result