In [20]: print None or False
-------> print(None or False)
False
In [21]: print False or None
-------> print(False or None)
None
This behaviour confuses me. Could someone explain to me why is this happening like this? I expected them to both behave the same.
The expression x or y
evaluates to x
if x
is true, or y
if x
is false.
Note that "true" and "false" in the above sentence are talking about "truthiness", not the fixed values True
and False
. Something that is "true" makes an if
statement succeed; something that's "false" makes it fail. "false" values include False
, None
, 0
and []
(an empty list).