问题
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