189 8069 5689

怎么实现python中super()多重继承-创新互联

小编给大家分享一下怎么实现python中super()多重继承,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!

创新互联建站从2013年成立,先为原平等服务建站,原平等地企业,进行企业商务咨询服务。为原平企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

实例:涉及多重继承

代码:

class Base(object):
    def __init__(self):
        print("enter Base")
        print("leave Base")


class A(Base):
    def __init__(self):
        print("enter A")
        super(A,self).__init__()
        print("leave A")


class B(Base):
    def __init__(self):
        print("enter B")
        super(B,self).__init__()
        print("leave B")

class C(A,B):
    def __init__(self):
        print("enter C")
        super(C,self).__init__()
        print("leave C")


c=C()

输出

C:\python36\python.exe E:/demo/testPyQt.py
enter C
enter A
enter B
enter Base
leave Base
leave B
leave A
leave C

Process finished with exit code 0

看完了这篇文章,相信你对怎么实现python中super()多重继承有了一定的了解,想了解更多相关知识,欢迎关注创新互联行业资讯频道,感谢各位的阅读!


标题名称:怎么实现python中super()多重继承-创新互联
分享链接:http://cdxtjz.cn/article/hjchj.html

其他资讯