python 面向对象十一 super函数

Posted lvye001

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 面向对象十一 super函数相关的知识,希望对你有一定的参考价值。

 

super函数用来解决钻石继承。

一、python的继承以及调用父类成员

父类:

class Base(object):

    def __init__(self):
        print("base init.")

普通方法调用父类:

class Leaf(Base):

    def __init__(self):
        Base.__init__(self)
        print("Leaf init.")

super方法调用父类:

class Leaf(Base):

    def __init__(self):
        super(Leaf, self).__init__()
        print("Leaf init.")

以上是关于python 面向对象十一 super函数的主要内容,如果未能解决你的问题,请参考以下文章