Three ways to call the parent class

Call the parent class method in three ways: 
1, self.run () method if they have run, then call their own,
using a self call the parent class method can not have the same name and the parent class method, follow mro order

2, the parent class name .run (self) need to pay attention to their own self incoming parameters self

3, Super Super (parent class name, self) .run (parameter 1, parameter 2)
Super (). RUN (parameter 1, parameter 2)
Super ( ) .__ init __ (parameter 1, parameter 2)

the nature of super: the class inheritance order, acquiring method (with the following codes understood) for a class of


class a (Object):
DEF the __init __ (Self):
Print ( 'a')


class B (Object):
DEF the __init __ (Self):
Print ( 'B')


class C (Object):
DEF the __init __ (Self):
Print ( 'C')


class D (A, C, B):
DEF the __init __ (Self) :
Super (C, Self) .__ the init __ ()
super(B, self).__init__()
print('D')

a = D()
print(D.mro())

Guess you like

Origin www.cnblogs.com/wjun0/p/11515407.html