super (call the init method)

'' '
Super behalf of that parent can.
You can use the super keyword calls the init method
syntax: super (subclass, self) .__ init __ (parameter 1, parameter 2, ...)
the same effect as: parent name .__ init __ (self, parameter 1, parameter 2, ...)
'' '
class Father ():
DEF __init __ (Self, name, House):
self.name = name
self.house = House
DEF Work (Self):
Print ( "breadwinner")
class Son (Father):
DEF __init__ (Self, name, House, Toy):
Super (Son, Self) .__ the init __ (name, House)
# Father .__ the init __ (Self, name, House)
self.toy = Toy

son1 = Son("son", "h", "t")
print(son1.toy)
print(son1.house)

 

Guess you like

Origin www.cnblogs.com/BKY88888888/p/11278783.html