Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

and / or operators return value [duplicate]

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.

like image 606
atp Avatar asked Dec 18 '10 11:12

atp


1 Answers

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 
like image 83
Frédéric Hamidi Avatar answered Sep 27 '22 01:09

Frédéric Hamidi