参考链接: https://stackoverflow.com/questions/4477850/and-or-operators-return-value/19187401#19187401
The and
and or
operators do return one of their operands, not a pure boolean value like True
or False:
>>> 0 or 42
42
>>> 0 and 42
0
Whereas not
always returns a pure boolean value:
>>> not 0
True
>>> not 42
False
Python docs:
Operation | Result | notes |
---|---|---|
x or y | if x is false, then y, else x | (1) |
x and y1 | if x is false, then x, else y | (2) |
not x | if x is false, then True, else False | (3) |