python - Python字典返回语法错误,无法识别错误

标签 python dictionary syntax-error

我已经创建了多个字典,现在遇到了最后一个字典的语法错误。我已经听完了命令,但找不到错误。我还有另外10个遵循相似格式的字典,但在打印时未显示任何错误。

这是该类中的命令:'c_equipment'

    c_Equipment = {
    1:
    {
        "Chain mail":"While wearing armour you have a disadvantage on Dexterity (Stealth) checks",
        "Greataxe",
        "Javelins":3,
        "Backpack", 
        "Blanket", 
        "Tinderbox", 
        "Rations": 2, 
        "Waterskin"
    },

    2:
    {
        "Chain mail",
        "Shield",
        'Warhammer',
        'Holy Symbol',
        'Backpack',
        'Crowbar',
        'Hammer',
        "Pistons":10,
        "Torches":10, 
        "Tinderbox", 
        "Ration":10, 
        'Waterskin',
        "Hempen Rope": 50, 
        "Masons Tools",
        "Dagger",
        "Playing Cards",
        "Common Clothes",
        "Pouch",
        "Rank-Insignia-(Sergeant)"
    }
    }

这是初始错误:
PS C:\Users\3com\Python> python test.py

File "test.py", line 5
"Greataxe",
          ^
 SyntaxError: invalid syntax

我尝试注释掉该行,但仍然显示错误。
PS C:\Users\3com\Python> python test.py

File "test.py", line 28
"Hempen Rope":50,
             ^
SyntaxError: invalid syntax

我只能通过注释掉大多数行来使字典能够打印。我相信该错误可能与具有数字值的键有关。但是我没有遇到其他格式相同的字典的问题

最佳答案

字典必须同时具有键和值。在您的情况下,有许多成员仅具有键而没有相应的值。

另一方面,只有键的花括号称为set,它是python中的另一个对象。

关于python - Python字典返回语法错误,无法识别错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58944974/

相关文章:

python - Tornado 协程在 Cython 中不起作用

python - 总结嵌套字典列表的最简洁方法

android - 如何在谷歌地图中获取解析 url 以获取有关 android 中位置和邻域的详细信息

php - react 本地错误,登录

c - 错误 : A compound literal of type not allowed

python - 脚本结束时不要终止 python 子进程

python - 如何在Python中使用另一个变量访问命名空间变量

python - 如何使用 Python 打开 DWG 文件扩展名?

python强制一个特定的键总是在字典的开头

java - Android Studio//导入语句错误//未使用导入语句