1. Son inherits the base class of parent, and can call the methods in the base class directly, but if you want to add a new property under the __init__ () method in the subclass, you need to call the __init__ () method of the base class actively, because the subclass does not automatically call the base class's __init__ () method. classSon (Parent):def __init__(self,name): Parent.__init__(self) self.name='Mic' defRun (self):Pass2. On top of the base class method, add some more actions:classSon (Parent):defRun (self):Print('---Add---') Parent.run (self)#Note: the instance created by the current class calls the run () method and is not implemented in the parent class; #--->> introducing super () classSun (Parent):defRun (self):Print('---Add---') Super (son,self). Run ()#The advantage of super () is that you do not need to specify a base class inheritance method, from all base classes #find this method to inherit; #-->> simplifies the super in Python3:super (). Run ()3. Attribute lookup order in multiple inheritance#two lines are available: location, specificity: #position, which indicates the position of the parameter at the time of inheritance; #particularity, indicating whether there is a parent class, and there are several layers of parent class; #In fact, the order of the base class lookup is determined by the C3 linearization algorithm, rather than the Internet . #depth first, breadth first such a simple algorithm; #In the process of inheriting the design of a class, there may be problems with validation, and the location and particularity conflict: classX (object):Passclas Y (X):Pass classZ (x, y):Pass #The above example will be an error; TypeError
Inherit from the face of the object | Python