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..
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..
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.