Why is `object` an instance of `type` and `type` an instance of `object`?

前端 未结 3 687
温柔的废话
温柔的废话 2020-12-09 04:51

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 inform

3条回答
  •  独厮守ぢ
    2020-12-09 05:30

    According to Python Data Model, everything in Python is an object and every object has an identity, a type and a value.

    object is the base class for all objects, type is also an object, so it is an instance of object, and same for object itself. Also type is the base class of all object types, so type of object is type, and same for type itself.

    This is my understanding, welcome to point out any mistakes.

提交回复
热议问题