The difference between type and object in Python after looking at the Python API, it finally dawned on you. Now summarized as follows:
First look at the description of object:
There are few or even a few words about object in Python:
- Class object
- The most base type
From the introduction, this is also Python's efforts to unify the type. So the object here is similar to the Java object class, and it can be inferred that this object is probably a "null class" that defines a type.
Then look at the description of type:
- class type (object)
- Type (object), the object ' s type
- Type (name, bases, Dict), a new type
- Methods defined here:
- __call__ (...)
- X.__call__ (...) <==> x (...)
- __cmp__ (...)
- x.__cmp__ (y) <==> cmp (x, y)
- __delattr__ (...)
- x.__delattr__ (' name ') <==> del x.name
- __getattribute__ (...)
- x.__getattribute__ (' name ') <==> x.name
- __hash__ (...)
- x.__hash__ () <==> hash (x)
- __repr__ (...)
- x.__repr__ () <==> repr (x)
- __setattr__ (...)
- x.__setattr__ (' name ', value) <==> X.name = value
- __subclasses__ (...)
- __subclasses__ (), List of immediate subclasses
- MRO (...)
- MRO () List
- Return a type ' s method resolution order
Since you should understand the difference between type and object. If you usually define the class, you want to be lazy as much as possible, you can inherit directly from the type, otherwise it is recommended to inherit object
Also put on the actual operation of the difference it:
The difference between type and object in Python