小编Squ*_*ald的帖子

字典和类

我有这个代码:

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.")
        }
Run Code Online (Sandbox Code Playgroud)

我想做这样的事情:

for item in WEAPONS:
    print(self.Name)
Run Code Online (Sandbox Code Playgroud)

我将如何在Python 3中进行此操作?

python iteration dictionary python-3.x

2
推荐指数
1
解决办法
62
查看次数

标签 统计

dictionary ×1

iteration ×1

python ×1

python-3.x ×1