What is a meta-class? Young people do not care about these details, we step-by-step!
001.
In the world of OOP, there is a word, "all things are objects."
classPerson (object): Name=Noneif __name__=="__main__": I=123s="Hello World"P=Person ()Print(Type (i))#<class ' int ' > Print(Type (s))#<class ' str ' > Print(Type (p))#<class ' __main__. Person ' > Print(Type (int))#<class ' type ' > Print(Type (str))#<class ' type ' > Print(Type (person))#<class ' type ' >
Let's take a look at the meaning of the above code
1, the first three sentences we can see: I is an instance of the int class, S is an instance of the Str class, p is an instance of the person class; #我下面要说的话 can make you feel uncomfortable
2, the last three sentences we can see:Int,str,person These classes are actually just an instance of the type class !
002.
I really did not tease you, type it really is a class Ah! Don't believe you help (type) look at
classtype (object)|type (object_or_name, bases, Dict)| Type (object), the object'S Type| Type (name, bases, Dict)a new type| |Methods defined here:| |__call__(Self,/, *args, * *Kwargs)|Call self as a function.| |__delattr__(Self, name,/) |Implement delattr (self, name).| |__dir__(...) |__dir__()List| Specialized__dir__Implementation forTypes| |__getattribute__(Self, name,/) |Return getattr (self, name).| |__init__(Self,/, *args, * *Kwargs)| Initialize self. See Help (Type) foraccurate signature.| |__instancecheck__(...) |__instancecheck__()BOOL| CheckifAn object isAn instance| |__new__(*args, * *Kwargs)| Create and returnA new object. See Help (Type) forAccurate signature.
----
Python meta-class programming