[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Clarification on Immutability please

On 1/21/20 8:41 PM, Jon Ribbens via Python-list wrote:
> Whether we call the link between 'foo' and (1, 2) a pointer or a
> reference is almost entirely irrelevant, the difference is essentially
> meaningless.

The issue is that in Python, objects and names are fairly distinct.

Unlike a language like C, where our variables actually hold the values 
themselves (and one type of value is a pointer), and we can set one 
variable value to be a pointer to another variable,? This isn't how 
Python works. In Python Names and Objects are distinct entities 
(although some objects have 'names' slots within them, like collections).

In C we can do something like

v = some_object;

p = &v

(Now p 'points to' v)

*p = some_other_object

and now v holds the value of some_other_object.

In Python

v = some_object

p = v

(Now p and v point to the same object)

p.mutate() can change the value of the shared object, but there is no 
way to make v refer to some new object.

The key distinction is that in Python, names are NOT objects, they only 
bind to objects, and thus names can't refer to some other name to let us 
rebind them remotely.

Richard Damon