<p>正常的赋值操作只是将新变量指向现有对象。<a href="http://docs.python.org/2/library/copy.html" rel="noreferrer">docs</a>解释了浅拷贝和深拷贝之间的区别:</p>
<blockquote>
<p>The difference between shallow and deep copying is only relevant for
compound objects (objects that contain other objects, like lists or
class instances):</p>
<ul>
<li><p>A shallow copy constructs a new compound object and then (to the extent possible) inserts references into it to the objects found in the original.</p></li>
<li><p>A deep copy constructs a new compound object and then, recursively, inserts copies into it of the objects found in the
original.</p></li>
</ul>
</blockquote>
<p>下面是一个小演示:</p>
<pre><code>import copy
a = [1, 2, 3]
b = [4, 5, 6]
c = [a, b]
</code></pre>
<p>使用普通赋值操作复制:</p>
<pre><code>d = c
print id(c) == id(d) # True - d is the same object as c
print id(c[0]) == id(d[0]) # True - d[0] is the same object as c[0]
</code></pre>
<p>使用浅拷贝:</p>
<pre><code>d = copy.copy(c)
print id(c) == id(d) # False - d is now a new object
print id(c[0]) == id(d[0]) # True - d[0] is the same object as c[0]
</code></pre>
<p>使用深层副本:</p>
<pre><code>d = copy.deepcopy(c)
print id(c) == id(d) # False - d is now a new object
print id(c[0]) == id(d[0]) # False - d[0] is now a new object
</code></pre>