欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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/搜索顺序/祖先树有关