首页 > 编程语言 > 详细

python 面向对象十一 super函数

时间:2018-10-24 21:18:11      阅读:156      评论:0      收藏:0      [点我收藏+]
 

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函数

原文:https://www.cnblogs.com/lvye001/p/9845960.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!