美文网首页
python基础 -- 继承super

python基础 -- 继承super

作者: fada492daf5b | 来源:发表于2018-01-25 12:53 被阅读0次

1. 作用

用于子类调用父类的方法

2. 操作

# super

class A(object):
    def __init__(self):
        print('enter A')
        print('exit A')

class B(A):
    def __init__(self):
        print('enter B')
        super(B, self).__init__()
        print('exit B')

class C(A):
    def __init__(self):
        print('enter C')
        super(C, self).__init__()
        print('exit C')

class D(C, B): # 
    def __init__(self):
        print('enter D')
        super(D, self).__init__()
        print('exit D')

if __name__ == '__main__':
    d = D()

# enter D
# enter C
# enter B
# enter A
# exit A
# exit B
# exit C
# enter D

相关文章

  • python基础 -- 继承super

    1. 作用 用于子类调用父类的方法 2. 操作

  • Python进阶-继承中的MRO与super

    Python进阶-继承中的MRO与super @(Python)[python, python进阶] [TOC] ...

  • Python - super()

    参考:Python : super没那么简单 一.单继承 1.Python2 2.Python3 二.多继承

  • Python的继承

    #Python继承的特点 总是从某个类继承 不要忘记调用 super().init 一定要用 super(Teac...

  • python类继承super

    在学习python类继承的时候,有没有被super迷惑。原来这只是新式类的标志而已,并且可以改写所有上面父类的相同属性

  • Python用super继承

    大神勿喷,正在学习中。将自己理解的分享出来而已,有兴趣的伙伴们可以指点指点一下,谢谢!! 直接上代码,理解的东西放...

  • ubuntu 下基于python深度学习

    一.python 的基本语法 <1>Python 类的定义、继承及使用对象 注意super()的使用,成员函...

  • python继承机制和Minxin模式

    python继承和访问父类和super python通过在类方法名旁边声明(父类名)来继承父类子类可以通过父类名....

  • python 神奇的super()

    我们都知道在python继承中,子类调用父类的方法是使用super()函数,在2.X里格式是super(mycla...

  • 怎么理解Python类中的super函数

    前言 在Python类的继承中,经常能看到super函数的存在,那super函数主要的作用,以及如何理解和使用好这...

网友评论

      本文标题:python基础 -- 继承super

      本文链接:https://www.haomeiwen.com/subject/udqpaxtx.html