如何将项添加到字典中的列表

时间:2015-01-14 12:44:19

标签: python dictionary

inventory = {
    'gold' : 500,
    'pouch' : ['flint', 'twine', 'gemstone'], # Assigned a new list to 'pouch' key
    'backpack' : ['xylophone','dagger', 'bedroll','bread loaf'],
    'pocket': ['seashell','strange berry','lint'] 
}

如何将50添加到存储在' gold'键

1 个答案:

答案 0 :(得分:0)

小学,沃森:

 inventory['gold'] += 50