Confusion found with and operator [duplicate]

為{幸葍}努か 提交于 2020-01-15 12:16:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!