【发布时间】:2014-04-25 10:34:29
【问题描述】:
我的代码是这样的,我想用super()来继承papa的特性,怎么做?
class Mama(object):
def __init__(self):
self.name = 'Mama'
def feature(self):
print "%s have big eyes" % self.name
class Papa(object):
def __init__(self):
self.name = 'Papa'
def feature(self):
print "%s have fierce beards" % self.name
class Offspring(Mama,Papa):
def __init__(self, name):
self.name = name
def feature(self):
super(Offspring, self).feature()
offspring = Offspring('Tommy')
offspring.feature()
# This will result "Tommy have big eyes"
【问题讨论】:
标签: python inheritance multiple-inheritance super