我已经创建了多个字典,现在遇到了最后一个字典的语法错误。我已经听完了命令,但找不到错误。我还有另外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/