码迷,mamicode.com
首页 > 编程语言 > 详细

python 面向对象十一 super函数

时间:2018-10-24 22:12:03      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:继承   body   object   钻石   code   ase   函数   elf   class   

 

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

标签:继承   body   object   钻石   code   ase   函数   elf   class   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!