How to access the NoneType type?

后端 未结 2 1117
逝去的感伤
逝去的感伤 2021-02-07 16:19

For example looking at the type of None, we can see that it has NoneType:

>>> type(None)
NoneType

However a NameErr

2条回答
  •  孤独总比滥情好
    2021-02-07 16:53

    As suggested by @dawg in the comments, you can do

    if (type(some_object).__name__ == "NoneType"):
      # Do some
      pass
    

    You can also do

    NoneType = type(None)    
    isinstance(some_object, NoneType) 
    

提交回复
热议问题