擅长:python、mysql、java
<p>只是一个del和slice的例子。</p>
<pre><code>In [28]: u = t = [1, 2,3,4]
In [30]: id(u) == id(t) # now the id is same,they point one obj
Out[30]: True
</code></pre>
<p>如果我们使用del运算符。</p>
<pre><code>In [31]: del t[0]
In [32]: t
Out[32]: [2, 3, 4]
In [33]: u
Out[33]: [2, 3, 4]
</code></pre>
<p>但是如果我们使用slice操作符。</p>
<pre><code>In [35]: t = t[1:]
In [36]: t
Out[36]: [2, 3, 4]
In [37]: id(t) == id(u)
Out[37]: False
In [39]: u
Out[39]: [1, 2, 3, 4]
</code></pre>
<p>我们发现t和u现在指向不同的obj,所以我们处理列表t,列表u不变。</p>