super顺序
class S():
def go(self):
print ("go s go!")
def stop(self):
print ("stop A stop!")
class A():
def go(self):
print ("go A go!")
def stop(self):
print ("stop A stop!")
# def pause(self):
# raise Exception("Not Implemented")
class B(A):
def go(self):
print("开始了B!")
super(B, self).go()
print ("go B go!")
class C(A):
def go(self):
print("开始了C!")
super(C, self).go()
print ("go C go!")
def stop(self):
super(C, self).stop()
print ("stop C stop!")
class D(B,C):
def go(self):
print('D开始了 啊 啊')
super(D, self).go()
print ("go D go!")
def stop(self):
super(D, self).stop()
print ("stop D stop!")
def pause(self):
print ("wait D wait!")
class E(B,C):
pass
a = A()
b = B()
c = C()
d = D()
e = E()
# 说明下列代码的输出结果
b.go()
输出:开始了B!
go A go!
go B go!
print('---b.go-----')
print('---c.go-----')
c.go()
输出:开始了C!
go A go!
go C go!
print('---d.go 开始-----')
d.go()
输出:
D开始了 啊 啊
开始了B!
开始了C!
go A go!
go C go!
go B go!
go D go!
print(D.mro())
输出: [<class '__main__.D'>, <class '__main__.B'>, <class '__main__.C'>, <class '__main__.A'>, <class 'object'>]
print('---d.go 结束----')
e.go()
开始了B!
开始了C!
go A go!
go C go!
go B go!
print(E.mro())
[<class '__main__.E'>, <class '__main__.B'>, <class '__main__.C'>, <class '__main__.A'>, <class 'object'>]
print('----v.stop----')
c.stop()
输出: stop A stop!
stop C stop!
写入自己的博客中才能记得长久