擅长:python、mysql、java
<p>您必须首先检查<code>dictionary</code>中是否存在作为键的“foo”。</p>
<p>您可以尝试:</p>
<pre><code>if "foo" in dict_name:
dict_name.append("new_append")
else:
dict_name["foo"] = ["first entry"]
</code></pre>
<p><strong>小建议:</strong>不要使用<code>dict</code>作为字典变量,因为它在Python中是关键字</p>