#-*-Coding:utf-8-*-<br data-filtered= "Filtered" >class A (object): Def __init__ (self, Xing, gender): # ! #1 Self.namea = "AAA" #! #2 self.xing = xing #! #3 Self.gender = gender #! #4 Self.funca () def Funca (self): print ("Function A:%s"% Self.namea) class B (a): Def __init__ (self, X ING, age): #! #5 Super (B, self). __init__ (Xing, age) #! #6 (age should be gender) Self.nameb = "BBB" #! #7 # #self. namea= "CCC" #! #8 # #self. xing = Xing.upper () #! #9 self.age = Age #! #10 def FUNCB (self): print ("Function B:%s"% SELF.NAMEB) def funca (self): print ("(Override) function A:%s "% Self.namea) b = B (" Lin ", 22) #! #11print (B.NAMEB) print (B.NAMEA) print (b.xing) #! #12print (b.age) print (b.geNDEr) #! #13b. FUNCB () B.funca ()
The output of the above program is:
(override) Function A:aaabbbaaalin2222function b:bbb (override) function a:aaa
The above procedure shows that if a method defined in the parent class is called in the parent class initialization method, and the method is overwritten by the quilt class, then super (B, self). The method called in the __init__ (Xing, age) invocation of the parent class will be the overridden method.
Python Super Initialization Understanding process