class A(object): pass class B(object): pass class C(A,B): # C 继承了 A 和 B pass class parent(): name='parent' age='50' def __init__(self): print('my name is {0}'.format(self.name)) def get_name(self): return self.name def get_age(self): return self.age class child(parent): name = 'child' age = 10 def __init__(self): print('my name is {0}'.format(self.name)) print('my age is {0}'.format(self.age)) def hello(self): print('hello world') a=child() a.hello() b=age()
返回结果:
my name is child
my age is 10
hello world