Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个不返回任何东西的函数,当我写的时候type(function())我得到 type NoneType。但什么时候type(function()) == None,反馈是False。为什么会这样?
type(function())
NoneType
type(function()) == None
False
None是 type 的单例对象NoneType,但与任何其他对象(嗯,任何没有奇数__eq__方法的对象)一样,它不等于它的类型。
None
__eq__
等效的检查是type(function()) == type(None), 或者,因为在这种情况下类型检查有点傻,所以function() is None.
type(function()) == type(None)
function() is None