1 class namespaces
Creating a class creates a namespace for a class that stores all the names defined in the class, called Properties of the class
And the good general properties of the class: Data Properties and Function properties
Where the data properties of a class are shared to all objects
Print (ID (g1.camp)) #引用的地址是一样的
Print (ID (garen.camp))
The output is:
364617767096
364617767096
Where the function property of a class is bound to all objects
Print (ID (g1.attack)) #两个引用地址不一样
Print (ID (garen.attack))
The output is:
1009949719304
1009951072464
Analysis: G1.attack is the function of Garen.attack, Python's class mechanism will garen function properties attack bound to g1,g 1 equivalent to get a pointer to Garen class attack function. In addition, G1.attack () passes G1 to the first parameter of attack.
2 object (instance) namespace
Creating an Object (instance) creates a namespace for an object (instance) that holds the name of the object (instance), called the property of the object (instance).
The Obj.name will first find the name in Obj's own namespace, find it in the class, find it in the class, and look for the parent class. Throws an exception if it is not found at the end.
Python\ class namespaces and Object namespaces