super用法

 

class A:
    def __init__(self):
        print("Enter A")
        print("Leave A")


class B(A):
    def __init__(self):
        print("Enter B")
        super(B, self).__init__()
        print("Leave B")


class C(A):
    def __init__(self):
        print("Enter C")
        super(C, self).__init__()
        print("Leave C")


class D(A):
    def __init__(self):
        print("Enter D")
        super(D, self).__init__()
        print("Leave D")


class E(B, C, D):
    def __init__(self):
        print("Enter E")
        super(E, self).__init__()
        print("Leave E")


E()

"""
Enter E
Enter B
Enter C
Enter D
Enter A
Leave A
Leave D
Leave C
Leave B
Leave E
"""

 

posted @ 2018-12-22 12:31  Operater  阅读(249)  评论(0编辑  收藏  举报