问题
I get following output with and operator
code
>>>0 and []
0
>>>[] and 0
[]
>>> 0 and ''
0
>>>'' and 0
''
I could not figure out about on what basis I m getting different result on the basis of placing of elements..
回答1:
From the docs on and:
The expression x and y first evaluates x; if x is false, its value is returned; otherwise, y is evaluated and the resulting value is returned.
In your case, because 0, '', and [] all evaluate to False, the first value in each of your expressions is being returned.
来源:https://stackoverflow.com/questions/24369368/confusion-found-with-and-operator