- Subclasses sometimes need to execute the parent class's constructor method
Class Annimal (object): def __init__ (self): print (' bar ') self.type = ' Animal ' class Shengwu (object): def _ _init__ (self): print (' Sengwu ') self.tc = ' Creature ' class Cat (Annimal,shengwu): def __init__ (self): SELF.N = ' Mao ' Super (cat,self). __init__ () m = Cat () print (m.__dict__)
The Cat class inherits the Annimal class and the Shengwu class, and in the construction method of the Cat class executes the construction method of the parent class super (cat,self). __init__ (), so the result:
However, the execution of the parent class is constructed by simply executing the Annimal __init__ () method, which does not implement the Shegnwu constructor method. This is identical to the order in which the inherited parent class executes the method in the parent class.
Child class execution Parent class constructor method