【发布时间】:2018-12-31 12:17:50
【问题描述】:
>>> dict = {}
>>> a=2
>>> if a is not None and dict is None:
... print("lol")
... else:
... print(" Print result is a")
...
result is a
为什么第一个if statement does not run? I am specifying that thedictis empty and that"a"`存在。
参考:https://docs.python.org/2/library/stdtypes.html#truth-value-testing
【问题讨论】:
-
{}不是None,None是None。
标签: python python-3.x dictionary false-positive truthiness