zoukankan      html  css  js  c++  java
  • 新式类的继承,广度优先

    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,C):
        def test(self):
            print('from D')
    class E(B,C):
        def test(self):
            print('from E')
    class F(D,E):
        def test(self):
            print('from F')
    f1=F()
    f1.test()
    print(F.__bases__)  #此用法为只向上找一步,即括号中内容。
    print(F.__mro__)    #此用法为查看其继承顺序,只有在新式类中才有。
    #新式类:F->D->E->B->C->A->object
    #有共同的就绕开,死活不找相同的父类,往宽的广的扩展。不到万不得已不走相同的,势不两立。






    class B:
        def test(self):
            print('from B')
    class C:
        def test(self):
            print('from C')
    class D(B,C):
        def test(self):
            print('from D')
    class E(B,C):
        def test(self):
            print('from E')
    class F(D,E):
        def test(self):
            print('from F')
    f1=F()
    f1.test()
    print(F.__bases__)  #此用法为只向上找一步,即括号中内容。
    print(F.__mro__)    #此用法为查看其继承顺序,只有在新式类中才有。
    #F->D->E->B->C->object





    class A(object):
        def test(self):
            print('from A')
    class B(A):
        def test(self):
            print('from B')
    class C:
        def test(self):
            print('from C')
    class D(B,C):
        def test(self):
            print('from D')
    class E(B,C):
        def test(self):
            print('from E')
    class F(D,E):
        def test(self):
            print('from F')
    f1=F()
    f1.test()
    print(F.__bases__)  #此用法为只向上找一步,即括号中内容。
    print(F.__mro__)    #此用法为查看其继承顺序,只有在新式类中才有。
    #不到万不得已不走相同的,宁愿走最深的。A是最深的,所以宁愿B去走最深的,也不去找相同的。
    #F->D->E->B->A->C->object
    
    
    
     
    
    
    
     
  • 相关阅读:
    bwapp之xss(blog)
    渗透测试平台bwapp简单介绍及安装
    用glob()函数返回目录下的子文件以及子目录
    常见编码解码脚本
    生成以指定字符为开头的md5值(6位数字)
    从1到n的阶乘的和(python)
    python循环解码base64
    BASE64编码原理分析脚本实现及逆向案例
    史上最完整的MySQL注入
    初探APT攻击
  • 原文地址:https://www.cnblogs.com/chedanlangren/p/6738911.html
Copyright © 2011-2022 走看看