Python 3: Why is `object` an instance of `type` an

2020-02-23 08:55发布

问题:

Edit: I don't think this is real duplicate of What are metaclasses in Python?, even though my question is partially answered at the very end of a long comment.

The linked question addresses metaclasses in general. My question is about the specific metaclass type. And from what I know after reading the answers the type metaclass cannot be implemented in pure Python. So my question is not only about "What are metaclasses?", moreover it is about the type/object relationship and how a metaclass can create itself, which is realized by "cheating" at the implementation level.

Also for people, who are not familiar with the concept of metaclasses both questions seem to be completely unrelated.


Initial Post:

I am a little bit confused about the object and type classes in Python 3. Maybe someone can clear up my confusion or provide some additional information.

My current understanding:

Every class (except object) inherits from a base class called object. But every class (including object) is also an instance of the class type, which is an instance of itself and object and also inherits from object.