Boolean in Python

Expressions may be linked together or negated using the boolean logical operators and, or, and not, all of which are Python keywords. These Boolean operations are in highest-to-lowest order of precedence in following Table. The not operator has the highest precedence and is immediately one level below all the comparison operators. The and and or operators follow, respectively.

Operator function
not expr logical NOT of expr (negation)
expr1 and expr2 logical AND of expr1 and expr2 (conjunction)
expr1 or expr2 logical OR of expr1 and expr2 (disjunction)

Example

>>> x,y = 3.1415926536, -1024
>>> x < 5.0
True
>>> not (x < 5.0)
False
>>> (x < 5.0) or (y >2.718281828)
True
>>> (x < 5.0) and (y > 2.718281828)
False
>>> not (x is y)
True