Python中的指针?`x.pointerDest = y.pointerDest`?

hhh*_*hhh 3 python pointers

我打破了我的旧问题,因为这里的野兽非常混乱.这个问题与这个答案答案有关.我尝试理解指针,甚至不确定它们是否存在于Python中.

# Won't change x with y=4
>>> x = 0; y = x; y = 4; x
0

# Won't change y
>>> x = 0; y = x; x = 2; y
0

#so how can I change pointers? Do they even exist in Python?
x = 0
y.pointerDestination = x.pointerDestination   #How? By which command?
x = 2
# y should be 0, how?
Run Code Online (Sandbox Code Playgroud)

[更新2:已解决]

也许,对存在矛盾的语句There are no pointers in Python.Python does not have the concept of a "pointer" to a simple scalar value..最后一个推断是否有指向其他东西的指针,使第一个语句无效?

Gre*_*ill 6

Python中的标量对象是不可变的.如果使用非标量对象(例如列表),则可以执行以下操作:

>>> x = [0]
>>> y = x
>>> y[0] = 4
>>> y
[4]
>>> x
[4]
>>> x is y
True
Run Code Online (Sandbox Code Playgroud)

Python没有指向简单标量值的"指针"的概念.