Relations in python and type of object

Transfer: https://segmentfault.com/a/1190000008938763

Learning python students know so few words

  • object class is the parent of all the new classes.

  • type is the class of all classes.

Then type and object is what does it matter?
object is a new class, we can object.__class__and object.__bases__to get the kind of nuclear object belongs to his parent.

>>> object.__class__
<type 'type'>

This shows that the class object is an instance of a metaclass type. This type is a class for all new classes this statement consistent.

>>> object.__bases__
()

This shows that the object class is already at the top of the chain of succession, is the parent of all classes.

>>> type.__class__
<type 'type'>

This shows that the type of class is its own type. That type metaclass is created by the type itself.

>>> type.__base__
<type 'object'>

This means that the type of the parent class metaclass is object.

Let's stroke a stroke, that is to say:
object class is created by the meta-class type, but the type and class inherits the object class. type metaclass category is a type metaclass itself created.

We put in the python built-in and user-created classes into which we can draw about the relationship diagram
image description

Briefly explain the other parts of the type and object relations.
int, float, str, boolean, tuple, dict, set and other built-in data types in fact, is the built-in classes.
is a special type of class, he is the class of all classes. So it is estimated to be the int type, etc. This is consistent, it is also lowercase?

Specific integer, float, dictionary, Ganso, etc. are examples of the above int, float, boolean, etc. in our daily program created.

We write custom code to create a class of two types, one is the new categories, one is a classic class.
The new class is a class type, its ultimate parent is the object.
Classic creator, is a classic class is a class called classobj thing, classobj class is the type.

The above text only based on their own understanding. Also there is an error, please correct me.

Guess you like

Origin www.cnblogs.com/acSzz/p/11111944.html