I have an understanding that object is an instance of type and type inherits from object. So the following relationships makes sense:
isinstance(object, type) # returns True, ok
issubclass(type, object) # returns True, ok
I also know that isinstance(a,b) checks whether a is an instance of either b or its bases. So, the following makes sense too:
isinstance(type, type) # returns True because it is translated to ....
isinstance(type, object) # which is True
What I cannot follow is why do the following statements return True.
isinstance(type, object) # returns True, but why?
isinstance(object, object) # returns True, but why?
Let me know if you know. Thanks.
objectis the root of the class hierarchy, so it is the ultimate parent class of every type, includingtypeandobject. That makesobjectits own parent class, which is one reason why you could not defineobjectin Python alone; it has to be dragged kicking and screaming out of thin air by the Python implementation.typeis a class, and all (built-in) classes are instances of the meta classtype. (Yes,typeis its own metaclass.) And sinceobjectis the base class oftype, thereforetypeis an instance ofobject.