我正在学习python中的继承,在我的练习中,我试图让Cat类从Animal类中继承comm()函数,但我得到None作为回报。谁能帮我弄清楚我在做什么错。
class Animal:
def __init__(self, name):
self.name = name
def comm(self, talk):
return self.name, talk
class Cat(Animal):
def comm(self, speak):
Animal.comm(self, speak)
if __name__=='__main__':
an = Animal('Person')
print '-----------Animal Results----------'
print an.comm('Speaks')
ct = Cat('Brainy')
print '-----------Cat Results----------'
print ct.comm('Mmmeeow')
运行上面的代码时,我得到以下结果:
-----------Animal Results----------
('Person', 'Speaks')
-----------Cat Results----------
None