Hi folks,
I'm trying to gain a deeper understanding of why it's possible to modify
list elements in-place *without* replacing them. For instance, why is the
below possible?

>>> class Dummy(object):
...     pass
...
>>> a = Dummy()
>>> b = Dummy()
>>> x = [a, b]
# modify list elements in-place
>>> x[1].name = 'The Dude'
>>> print x[1].name
The Dude
>>> x[0].name = 'The Stranger'
>>> for item in x:
...     print item.name
...
The Stranger
The Dude
# modify elements by iterating over the list
>>> for item in x:
...     item.start_date = 2010

>>> for item in x:
...     print item.name, item.start_date
...
The Stranger 2010
The Dude 2010

I figured the below quote offers the beginning of an explanation on this
page:
"The list object stores pointers to objects, not the actual objects
themselves."
http://effbot.org/zone/python-list.htm

But I was hoping you all could provide a more in-depth explanation, or even
better, direct me to some other readings and python code that implements
this behavior. Can anyone point me in the right direction for further study?

Thanks!
Serdar
_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to