給予代碼:關於繼承和超()
class Character():
def __init__(self, name):
self.name = name
self.health = 50
self.damage = 10
class Warrior(Character):
def __init__(self, name, weapon, armor):
super(Character).__init__()
self.weapon = weapon
self.armor = armor
self.strength = 10
self.dexterity = 5
self.intelligence = 5
Doug = Character("Doug")
Mark = Warrior("Mark", "Axe", None)
爲什麼不Warrior
類繼承自Character
類health
?
我需要做些什麼才能打印Mark.health
?
'超'是相當棘手的幾個原因;請參閱http://stackoverflow.com/q/222877/1256452 – torek