标签:关系 nbsp print alt mamicode image 开始 bsp color
1 class D: 2 def show(self): 3 print("i am D") 4 pass 5 6 class C(D): 7 pass 8 9 class B(C): 10 11 pass 12 13 class G: 14 pass 15 16 class F(G): 17 pass 18 19 class E(F): 20 def show(self): 21 print("i am E") 22 pass 23 24 class A(B, E): 25 pass 26 27 a = A() 28 a.show()
执行结果是"i am D",左边具有深度优先权,当一条路走到黑也没找到的时候,才换另一条路。可见,在这种继承结构关系中,搜索顺序是这样的:
标签:关系 nbsp print alt mamicode image 开始 bsp color
原文地址:https://www.cnblogs.com/shuimohei/p/11617452.html