AggieDan04 a écrit :
On Apr 20, 2:03 am, bdb112 <boyd.blackw...@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

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to