zoukankan      html  css  js  c++  java
  • Python类的继承顺序__mro__

    class A:
        def test(self):
            print('print from A')
        pass
    
    class B(A):
        # def test(self):
        #     print('print from B')
        pass
    
    class C(A):
        def test(self):
            print('print from C')
        pass
    
    class D(B):
        # def test(self):
        #     print('print from D')
        pass
    
    class E(C):
        # def test(self):
        #     print('print from E')
        pass
    
    class F(D,E):
        # def test(self):
        #     print('print from F')
        pass
    
    f=F()
    print(F.__mro__)
    f.test()
    输出:
    class A:
        def test(self):
            print('print from A')
        pass
    
    class B(A):
        # def test(self):
        #     print('print from B')
        pass
    
    class C(A):
        def test(self):
            print('print from C')
        pass
    
    class D(B):
        # def test(self):
        #     print('print from D')
        pass
    
    class E(C):
        # def test(self):
        #     print('print from E')
        pass
    
    class F(D,E):
        # def test(self):
        #     print('print from F')
        pass
    
    f=F()
    print(F.__mro__)
    f.test()
    
    写入自己的博客中才能记得长久
  • 相关阅读:
    数据库优化
    List,map,Set区别
    ID选择器
    最简单的添加删除行操作
    JQ2
    最简单的JQ实现
    20180416
    一行细分的HTML写法
    out参数的使用
    结构的使用
  • 原文地址:https://www.cnblogs.com/heris/p/14764627.html
Copyright © 2011-2022 走看看