None Python error/bug?

前端 未结 4 2039
忘了有多久
忘了有多久 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:57

    You can try:

    >>> variable = None
    >>> isinstance(variable,type(None))
    True
    >>> variable = True
    >>> isinstance(variable,type(None))
    False
    

    isinstance takes 2 arguments isinstance(object, classinfo) Here, by passing None you are setting classinfo to None, hence the error. You need pass in the type.

提交回复
热议问题