and [True,True] --> [True, True]?????

Pascal Chambon chambon.pascal at wanadoo.fr
Mon Apr 20 15:00:12 EDT 2009


AggieDan04 a écrit :
> On Apr 20, 2:03 am, bdb112 <boyd.blackw... at gmail.com> wrote:
>   
>> Is there any obvious reason why
>> [False,True] and [True,True]
>> gives [True, True]
>>
>> Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
>> (Intel)]
>>     
>
> X and Y == (Y if X else X)
> X or Y == (X if X else Y)
>
> [False, True] is true, so the and operator returns the second argument.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>   
My 0.02$ comments : people used to simulate ternary operator (the 
"bool?res1:res2" of c++) with combinations like "bool and res 1 or res 
2", but actually it doens't work in all cases (if res1 evaluates to 
false, res2 will ALWAYS be returned), so we'd better use "res1 if bool 
else res2", the python dedicated operator B-)


Regards,
Pascal

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090420/bc030d6d/attachment-0001.html>


More information about the Python-list mailing list