我有这个密码:
class weapon():
def __init__(self, Name, Type, Description):
self.Name=Name
self.Type=Type
self.Description=Description
WEAPONS = { "starterSword":weapon("Starter Sword", "Sword", "A short, stunt steel sword."),
"basicSword":weapon("Basic Sword", "Sword", "A basic steel sword.")
}
我想这样做:
for item in WEAPONS:
print(self.Name)
在python3中我该如何做呢?你知道吗
正如@MSeifert所说。不管怎样,遍历字典会为每个项提供键和值。所以这也是可行的:
顺便问一下:你为什么用字典?因为每种武器都有自己的名字。你知道吗
只需迭代values:
最好是在类(OOP)中编写方法并调用它们,而不必编写大量代码
会给你想要的输出。你知道吗
相关问题 更多 >
编程相关推荐