【发布时间】:2014-02-17 18:25:04
【问题描述】:
此时我已经在 Python 中搞砸了大约一个半月,我想知道:有没有办法为该类中的所有对象打印一个类变量的值?例如(我在做一个小游戏):
class potions:
def __init__(self, name, attribute, harmstat, cost):
self.name = name
self.attribute = attribute
self.harmstat = harmstat
self.cost = cost
Lightning = potions("Lightning Potion", "Fire", 15, 40.00)
Freeze = potions("Freezing Potion", "Ice", 20, 45.00)
我希望能够打印一份所有药水名称的列表,但我找不到这样做的方法。
【问题讨论】:
标签: python class object attributes