Type literal meaning is a kind that can be understood as a stencil, generating various instances through the mold. The built-in function type () in Python allows you to see the concrete type of the instance.
What kind of type is it? Take a look at the following example.
>>> type (BOOL)
<type ' type ' >
>>> Type (str)<type'type'>>>> Type (int)<type'type'>>>> Type (list)<type'type'>>>> Type (dict)<type'type'>>>> Type (set)<type'type'>>>> Type (type)<type'type'>
As you can see, bool,str,int,list,dict,set are type types, and these are basic types.
Take a look at these types of instances:
>>>type (True)<type'BOOL'>>>>type (False)<type'BOOL'>>>> Type ('1234')<type'Str'>>>> type ([1,2,3,4])<type'List'>>>> type ({1,2,3,4})<type'Set'>>>> type ({1:'a', 2:'b', 3:'C', 4:'D'})<type'Dict'>
There is also a type called Class, which is also a template, and its instance is called object.
class Myobjecta (object): ... Pass >>> type (myobjecta)'type'>
Class has an inheritance relationship, what kind of subclass is it? All classes in Python inherit object, and what type is Object?
class Myobjectsuba (myobjecta): ... Pass >>> type (myobjectsuba)'type'>>>> type ( Object)'type'>
It appears that as long as it is class, the types are type. And look at the types of objects they instantiate.
>>> my_object_a = myobjecta ()>>> type (my_object_a)<class' myobjecta '>>>> my_object_sub_a = Myobjectsuba ()>>> type (my_object_sub_a) <class'myobjectsuba'>
If an object is an instance of who it is, then it is the type of person.
Take a look at __bases__, __bases__ is also a built-in function to see the inheritance of class. Let's look at the following kinds of inherited relationships.
class MYOBJECTB (object): ... Pass class myobjectc (myobjecta, MYOBJECTB) : ... Pass >>> MYOBJECTC. __bases__ (<class'myobjecta';, <class' myobjectb'>)
MYOBJECTC inherit Myobjecta, MYOBJECTB. You can see that the __bases__ of MYOBJECTC is a tuple that contains myobjecta and MYOBJECTB.
You can try the Python tutor
Myobjecta's __bases__ is an object, verified under:
Myobjecta. __bases__ ('object';,)
What is the __base__ of the object?
>>> object. __bases__ ()
An empty tuple.
What is the __bases__ of type?
>>> type. __bases__ ('object';,)
Object
Finally, we can sort out a picture like this.
Python Type and __bases__