Simple object reference

Chris Rebert clp2 at
Sun Nov 15 00:40:05 CET 2009

On Sat, Nov 14, 2009 at 3:25 PM, AON LAZIO <aonlazio at> 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. Modifying the
list does not change what values the names a, b, and c have. There is
no Python-level notion of pointers.

> for i in range(len(slist)):
> slist[i] = 5

This modifies the contents of the list, it does not affect any other

> print slist
> print a,b,c
> I got this
> [5, 5, 5]
> None None None
>     Question is how can I got all a,b,c variable to have value 5 also?

Use tuple unpacking:

#at start of code
slist = [None]*3
#at end of code
a, b, c = slist

I would also recommend reading for a good explanation of
how Python's variables work.


More information about the Python-list mailing list