47. 面向对象中super的作用?

用于子类继承父类的方法

class FooParent(object):
    def __init__(self):
        self.parent = 'I\'m the parent.'
        print('Parent')
        print('1111')

    def bar(self, message):
        print("%s from Parent" % message)


class FooChild(FooParent):
    def __init__(self):
        # super(FooChild,self) 首先找到 FooChild 的父类(就是类 FooParent),然后把类B的对象 FooChild 转换为类 FooParent 的对象
        super(FooChild, self).__init__()
        print('Child')
发布了72 篇原创文章 · 获赞 7 · 访问量 8960

猜你喜欢

转载自blog.csdn.net/CHERISHGF/article/details/105300148