擅长:python、mysql、java
<p>如果你想在“白金”键上加60</p>
<pre><code>inventory ["Platinum"] += 60
</code></pre>
<p>如果你想保持500的值,同时又有60的值,你需要一些东西来包含它们,比如一个列表。在</p>
<p>你可以用一个列表初始化你的“白金”值,然后在它上面追加500和60。在</p>
^{pr2}$
<p>或者您可以使用defaultdict使其稍微简单一些。在</p>
<pre><code>from collections import defaultdict
inventory = defaultdict (list) # every missing value is now a list.
inventory ["Platinum"].append (500) # add 500 to the list.
inventory ["Platinum"].append (60) # add 60 to the list.
inventory ["pouch"] = ['Flint', 'twine', 'gemstone'] # create a new key with a new value.
inventory['animals'].extend(['Elephant', 'dog','lion']) # extend list to include.
inventory['pouch'].remove('Flint')
</code></pre>