0
我有這樣一本字典:如何刪除詞典列表項
inventory = {'gold' : 500,
'pouch' : ['flint', 'twine', 'gemstone'],
'backpack' : ['xylophone','dagger', 'bedroll','bread loaf']}
我怎樣才能從中取出匕首?
我嘗試這樣做:
inventory["backpack"][1].remove()
或
del inventory["backpack"][1]
但它使此錯誤:
Traceback (most recent call last):
File "python", line 15, in <module>
TypeError: 'NoneType' object has no attribute '__getitem__'
'''del inventory [「backpack」] [1]'''對我很好。 – Danstahr
這讓我這個錯誤:追溯(最近呼叫最後): 文件「python」,第15行,在 TypeError:'NoneType'對象不支持刪除項目 –
Sina