擅长:python、mysql、java
<p><code>_update</code>方法就地修改集合并返回None。不带<code>update</code>的方法返回一个新对象。您几乎肯定不想做<code>x = s.update(t)</code>,因为这会将<code>x</code>设置为无。</p>
<pre><code>>>> x = set([1, 2])
>>> x.intersection(set([2, 3]))
set([2])
>>> x
set([1, 2])
>>> x.intersection_update(set([2, 3]))
>>> x
set([2])
>>> x = x.intersection_update(set([2, 3]))
>>> print x
None
</code></pre>
<p><code>_update</code>方法添加的功能是修改现有集合的能力。如果在多个对象之间共享一个集,则可能需要修改现有集,以便共享该集的其他对象可以看到更改。如果你只是创建一个新的集合,其他对象就不会知道它。</p>