I was watching a 2007 video on Advanced Python or Understanding Python, and at 18'27" the speaker claims "As some may know in Python and
and or
return one of the two values, whereas not
returns always a boolean." When has this been the case?
As far as I can tell, and
and or
return booleans, too.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With