python Super()的奇特美
程序员文章站
2022-05-21 11:21:41
...
python Super()的奇特美
super()在类继承中并不是调用父类的意思
比如:
class A:
def do(self):
print("this is a A class do")
class B:
def do(self):
print("this is a B cladd do")
class C:
def do(self):
print("this is a C class do")
class D(B,C):
def do(self):
super().do()
class E(D,A):
def do(self):
super().do()
class F(A,D):
def do(self):
super().do()
d = D()
d.do()
e = E()
e.do()
f = F()
f.do()
==你能猜到答案吗 ?==这和MRO/搜索顺序/祖先树有关
上一篇: Python的多重继承问题
下一篇: Python3 的多类继承问题