<p>不要混淆引用的指针。他们不是一回事。指针只是指向对象的地址。在python中,您不能真正访问对象的地址,只能访问它们的引用。在</p>
<p>当你把一个对象赋给一个变量时,你就是在给变量分配一个对某个对象的引用。在</p>
<pre><code>x = 0
# x is a reference to an object `0`
y = [0]
# y is a reference to an object `[0]`
</code></pre>
<p>python中的一些对象是可变的,这意味着您可以更改对象的属性。其他的是不可变的,这意味着您不能更改对象的属性。在</p>
<p><code>int</code>(标量对象)是不可变的。一个<code>int</code>的属性没有你可以改变的(又称变异)。在</p>
^{pr2}$
<p>另一方面,<code>list</code>(非标量对象)是可变的。您可以更改列表中的各个元素以引用其他元素。在</p>
<pre><code>y[0] = 20 # changes the 0th element of the list to `20`
</code></pre>
<p>在您展示的示例中:</p>
<pre><code>>>> x = [0]
>>> y = [x]
</code></pre>
<p>你不是在处理指针,而是在处理对具有特定值的列表的引用。<code>x</code>是一个包含单个整数<code>0</code>的列表。<code>y</code>是一个包含对<code>x</code>所指内容的引用的列表(在本例中,是<code>[0]</code>)。在</p>
<p>您可以更改<code>x</code>的<em>内容,如下所示:</p>
<pre><code>>>> print(x)
[0]
>>> x[0] = 2
>>> print(x)
[2]
</code></pre>
<p>您可以更改<code>x</code>到<code>y</code>引用的列表的<em>内容</em>:</p>
<pre><code>>>> print(x)
[2]
>>> print(y)
[[2]]
>>> y[0][0] = 5
>>> print(x)
[5]
>>> print(y)
[[5]]
</code></pre>
<p>您可以更改<code>y</code>的<em>内容</em>以引用其他内容:</p>
<pre><code>>>> print(y)
[[5]]
>>> y[0] = 12345
>>> print(x)
[5]
>>> print(y)
[12345]
</code></pre>
<p>它与Java或C等语言的语义基本相同。您不直接使用指向对象的指针(尽管您是间接使用指针,因为实现在幕后使用指针),而是对对象的引用。在</p>