Why 'issubclass(object, type)' gives false (in python)?

眉间皱痕 提交于 2019-12-25 00:49:59

问题


I'm confused in python class hierarchy.

I want to know the relation between type and object.

object is the top of 'issubclass()' function. type is the top of 'thing.class' and 'type(thing)'. (I intentionally didn't use the word object again to avoid confusion. instead I used thing.)

Surprisingly isinstance(object, type) and isinstance(type, object) both return true.

Explain the hierarchy in detail. Thanks

I mean which one was written first? type? or object?


回答1:


In Python, everything is an object, so:

isinstance(type, object) == True

Since object is a type constructor, it's a subclass of type:

isinstance(object, type) == True


来源:https://stackoverflow.com/questions/59227072/why-issubclassobject-type-gives-false-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!