None Python error/bug?

前端 未结 4 2129
忘了有多久
忘了有多久 2021-02-05 07:33

In Python you have the None singleton, which acts pretty oddly in certain circumstances:

>>> a = None
>>> type(a)


        
4条回答
  •  我寻月下人不归
    2021-02-05 07:51

    None is a value(instance) and not a type. As the error message shows, isinstance expects the second argument to be a type.

    The type of None is type(None), or Nonetype if you import it (from types import NoneType)

    Note: the idiomatic way to do the test is variable is None. Short and descriptive.

提交回复
热议问题