bool

https://docs.python.org/3/library/constants.html

https://docs.python.org/3/library/functions.html#bool

INTRODUCTION

Any object can be tested for truth value.

Objects considered false:

Everything else is considered true.

True and False are instances of the bool class which is inherited from int. In numeric contexts (for example when used as the argument to an arithmetic operator), False and True behave like the integers 0 and 1, respectively.


>>> True + True
2
>>> True * True
1
>>> True - True
0
>>> False + False
0

BOOLEAN OPERATIONS

A or B, A and B, not A (ascending priority).

(A or not B and C) is interpreted as A or ((not B) and C).

(not A == B) is interpreted as not (A == B) (== is a non-Boolean operator!).

Use parentheses () in case of doubt.

and and or are short-circuit operators:

COMPARISONS

A == B, A != B, A < B, A <= B, A > B, A >= B.

Identity tests: A is B [id(A) == id(B)], A is not B.

(x in S) and (x not in S) operations are supported by types that are iterable or implement the __contains__() method.