類的繼承順序:按照mro線性順序列表查找,經典類按照深度優先查找,新式類按照廣度優先查找python
經典類:python2中分經典類和新式類,經典類形如--class A,和新式類,形如--class A(object)ide
新式類:python3中全是新式類spa
深度優先:從左自右查找分支,先第一個分支一直查到基類,若無再查第二個分支。。。code
廣度優先:從左自右查找分支,先查第一個分支,不查到基類,直到最後一個分支才查找基類。。。blog
class A: def Test(self): print('A') pass class G: def Test(self): print('G') pass class BL(A): # def Test(self): # print('BL') pass class BR(A): def Test(self): print('BR') pass class F(G): # def Test(self): # print('F') pass class CL(BL): # def Test(self): # print('CL') pass class CR(BR): def Test(self): print('CR') pass class D(CL,CR,F): # def Test(self): # print('D') pass d=D() d.Test()#D-->CL--BL--CR--BR--A--F--G,PY3中廣度優先查找 print(D.mro()) #[<class '__main__.D'>, <class '__main__.CL'>, <class '__main__.BL'>, <class '__main__.CR'>, <class '__main__.BR'>, <class '__main__.A'>, <class '__main__.F'>, <class '__main__.G'>, <class 'object'>]
調用父類:super().__init__()父類初始化繼承