【发布时间】:2021-08-15 14:02:06
【问题描述】:
【问题讨论】:
标签: python oop console-application
【问题讨论】:
标签: python oop console-application
您可以使用继承并编写类似的内容:
class Item:
def __init__(self, name: str) -> None:
self.name = name
class Character:
def __init__(self, weapon: Item) -> None:
self.weapon = weapon
class Warrior(Character):
def __init__(self, weapon: Item) -> None:
# some attributes
super().__init__(weapon=weapon)
class Tanker(Character):
def __init__(self, weapon: Item) -> None:
# some attributes
super().__init__(weapon=weapon)
sword = Item(name="Sword")
axe = Item(name="Axe")
warrior = Warrior(weapon=sword)
tanker = Tanker(weapon=axe)
【讨论】: