Determine the type of an object?

后端 未结 13 2128
余生分开走
余生分开走 2020-11-22 05:50

Is there a simple way to determine if a variable is a list, dictionary, or something else? I am getting an object back that may be either type and I need to be able to tell

13条回答
  •  有刺的猬
    2020-11-22 06:06

    be careful using isinstance

    isinstance(True, bool)
    True
    >>> isinstance(True, int)
    True
    

    but type

    type(True) == bool
    True
    >>> type(True) == int
    False
    

提交回复
热议问题