1、继承的实现原理:经典类:深度优先(一路到底),新式类:广度优先

只有在python2中才分新式类和经典类,python3中统一都是新式类

2.在python2中,没有显式的继承object类的类,以及该类的子类,都是经典类
3.在python2中,显式地声明继承object的类,以及该类的子类,都是新式类
4.在python3中,无论是否继承object,都默认继承object,即python3中所有类均为新式类

print(F.__mro__)

class A(object):
    def test(self):
        print('from A')

class B(A):
    def test(self):
        print('from B')

class C(A):
    def test(self):
        print('from C')

class D(B):
    def test(self):
        print('from D')

class E(C):
    def test(self):
        print('from E')

class F(D,E):
    # def test(self):
    #     print('from F')
    pass
f1=F()
f1.test()
print(F.__mro__) #只有新式才有这个属性可以查看线性列表,经典类没有这个属性

#新式类继承顺序:F->D->B->E->C->A
#经典类继承顺序:F->D->B->A->E->C
#python3中统一都是新式类
#pyhon2中才分新式类与经典类
View Code

相关文章:

  • 2022-12-23
  • 2021-05-16
  • 2021-10-09
  • 2021-09-30
  • 2022-12-23
  • 2021-12-02
  • 2021-11-29
猜你喜欢
  • 2021-10-05
  • 2021-12-24
  • 2021-05-20
  • 2021-09-21
  • 2021-08-17
  • 2021-12-25
  • 2022-12-23
相关资源
相似解决方案