本文介绍了False或None与None或False的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
In [20]: print None or False
-------> print(None or False)
False
In [21]: print False or None
-------> print(False or None)
None
这种行为使我感到困惑.有人可以向我解释为什么会这样吗?我希望他们的行为都一样.
This behaviour confuses me. Could someone explain to me why is this happening like this? I expected them to both behave the same.
推荐答案
如果x
为true,则表达式x or y
的值为x
;如果x
为false,则为y
.
The expression x or y
evaluates to x
if x
is true, or y
if x
is false.
请注意,以上句子中的"true"和"false"是指真实性",而不是固定值True
和False
.如果是"true",则使if
语句成功.某些假"的东西会使它失败. "false"值包括False
,None
,0
和[]
(空列表).
Note that "true" and "false" in the above sentence are talking about "truthiness", not the fixed values True
and False
. Something that is "true" makes an if
statement succeed; something that's "false" makes it fail. "false" values include False
, None
, 0
and []
(an empty list).
这篇关于False或None与None或False的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!