问一个python逻辑运算符的初级问题!

five = 5two = 2zero = 0five and two # 2two and five # 5five and zero # 0我想知道这个是怎么运算的呢?谁能详细讲解一下呢,谢谢

第1个回答  2012-02-26
and 是短路运算符,python中,非0值都代表逻辑真,逻辑运算时返回最后运算的结果。例如:
5 and 2 ,返回最后运算的2。
2 and 5,返回5。
5 and 0,返回0。
0 and 5,还是返回0。因为0代表假,and 不再进行运算了,直接被短路,返回0