擅长:python、mysql、java
<p>Python主要实现了<a href="http://en.wikipedia.org/wiki/Command-query_separation" rel="noreferrer">command-query separation</a>:mutators返回<code>None</code>(带有实用主义诱导的异常,如<code>pop</code>;-),因此它们不可能与访问器混淆(同样,赋值不是表达式,语句-表达式分离在那里,等等)。</p>
<p>这并不意味着在你真正想要的时候没有很多方法可以把事情合并起来,例如,<code>dict(a, **award_dict)</code>使一个新的dict非常像你看起来希望返回的dict<code>.update</code>——所以如果你真的觉得它很重要,为什么不使用它呢?</p>
<p><strong>编辑</strong>:顺便说一句,在您的特定情况下,不需要创建<code>a</code>一路上,或者:</p>
<pre><code>dict(name=name, description=desc % count, points=points, parent_award=parent,
**award_dict)
</code></pre>
<p>创建一个dict,其语义与您的<code>a.update(award_dict)</code>完全相同(包括在发生冲突的情况下,<code>award_dict</code>中的条目重写您显式给出的那些条目;要获得其他语义,即要使显式条目“赢得”此类冲突,请将<code>award_dict</code>作为唯一的位置<e em>参数传递,<em>在</em>关键字之前一个,失去了<code>**</code>形式的<code>dict(award_dict, name=name</code>等)。</p>