1. 程式人生 > >經典類深度優先,新式類是廣度優先

經典類深度優先,新式類是廣度優先

pre self 深度優先 bsp -- -o style class a print

#深度優先和廣度優先
#新式類基本都是廣度優先
class A:#如果沒有具體繼承類默認繼承類是object
    def test(self):
        print(A)
class B(A):
    pass
    # def test(self):
    #     print(‘B‘)
class C(A):
   pass
    # def test(self):
    #     print(‘C‘)
class D(B):
    # def test(self):
    #     print(‘D‘)
    pass
class E(C):
    
# def test(self): # print(‘E‘) pass class F(D,E):#新式類從左往右 #F-D-B不找A,然後回到右邊從E-C-A---object # def test(self): # print(‘F‘) pass f1=F() f1.test() print(F.mro())#mro列表F-D-B不找A,然後回到右邊從E-C-A---object

經典類深度優先,新式類是廣度優先