class FooParent(object):
def __init__(self):
self.parent = 'I\'m the parent.'
print ('Parent')
def bar(self,message):
print ("%s from Parent" % message)
class FooChild(FooParent):
def __init__(self):
super(FooChild,self).__init__()
print ('Child')
def bar(self,message):
super(FooChild, self).bar(message)
print ('Child bar fuction')
print (self.parent)
if __name__ == '__main__':
fooChild = FooChild()
fooChild.bar('HelloWorld')
结果:
Parent 这是print的结果父类打印
Child 子类打印
到这里已经执行完FooChild()这一步了
HelloWorld from Parent 父类赋值打印
Child bar fuction 子类打印
I'm the parent. 打印self.parent是父类的值