多繼承中,如有多個方法存在的調用:
class P1:
def foo(self):
print('Called P1-foo()')
class P2:
def foo(self):
print('Called P2-foo()')
def bar(self):
print('Called P2-bar()')
class C1(P1,P2):
pass
class C2(P1,P2):
def bar(self):
print('Called C2-bar()')
class GC(C1,C2):
pass
gc = GC()
gc.foo()
P2.foo(gc)
gc.bar()
P2.foo(gc)
運行結果:
Called P1-foo()
Called P2-foo()
Called C2-bar()
Called P2-foo()