Simple object reference

Chris Rebert clp2 at rebertia.com
Sat Nov 14 22:19:19 EST 2009


On Sat, Nov 14, 2009 at 6:53 PM, Terry Reedy <tjreedy at udel.edu> wrote:
> Chris Rebert wrote:
>> On Sat, Nov 14, 2009 at 3:25 PM, AON LAZIO <aonlazio at gmail.com> wrote:
>>> Hi, I have some problem with object reference
>>> Say I have this code
>>>
>>> a = b = c = None
>>> slist = [a,b,c]
>>
>> Values are stored in the list, not references to names.
>
> That is not right either, or else newbies would not be surprised by
>>>> a = [0]
>>>> b = [a]
>>>> b[0][0] = 1
>>>> a
> [1]
>
> Subscriptable collections associate subscripts with objects.
> Namespaces associated names with objects.
> In either case, if you change the object, you change it, regardless of how
> you access it, such as by means of other associations.
> If you replace an association by associating a name or subscript with a new
> object, the old object is untouched (unless that was its last association)
> and other access methods by means of other associations are not affected.

Okay, I should have technically said "references to objects" rather
than "values", but in any case, names themselves are certainly not
referenced or the following would print "[1]".

>>> a = [0]
>>> b = [a]
>>> a = [42]
>>> b[0][0] = 1
>>> a
[42]

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list