我已经看到下面的代码:继承查询在Python
class Spell(object):
def __init__(self, incantation, name):
self.name = name
self.incantation = incantation
def __str__(self):
return self.name + ' ' + self.incantation + '\n' + self.get_description()
def get_description(self):
return 'No description'
def execute(self):
print self.incantation
class Accio(Spell):
def __init__(self):
Spell.__init__(self, 'Accio', 'Summoning Charm')
class Confundo(Spell):
def __init__(self):
Spell.__init__(self, 'Confundo', 'Confundus Charm')
def get_description(self):
return 'Causes the victim to become confused and befuddled.'
def study_spell(spell):
print spell
我不明白,为什么下面的代码输出Summoning Charm Accio No description
。我很困惑为什么打印No description
。
spell = Accio()
print spell
谢谢
它的代码应该有“子类”,或缩进怪异? – matsjoyce 2014-09-29 17:49:25