classParent(object): def__init__(self): print('hello i am parent') classChild(Parent): def__init__(self): print('hello i am child') super(Child, self).__init__() #python3 括弧内的参数可以省略 # 当前类 类的实例
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# coding:utf-8
classParent(object): def__init__(self, p): print('hello i am parent %s ' % p)
classChild(Parent): def__init__(self, c, p): # super(Child, self).__init__(p) super().__init__(p) # super(Child, self).__init__('parent') 也可以 print('hello i am child %s ' % c)
if __name__ == '__main__': c = Child(c='Child', p='Parent')