Hi folks,<br>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?<br><br>>>> class Dummy(object):<br>
... pass<br>... <br>>>> a = Dummy()<br>>>> b = Dummy()<br>>>> x = [a, b]<br># modify list elements in-place<br>>>> x[1].name = 'The Dude'<br>>>> print x[1].name<br>
The Dude<br>>>> x[0].name = 'The Stranger'<br>>>> for item in x:<br>... print <a href="http://item.name" target="_blank">item.name</a><br>... <br>The Stranger<br>The Dude<br># modify elements by iterating over the list<br>
>>> for item in x:<br>... item.start_date = 2010<br><br>>>> for item in x:<br>... print <a href="http://item.name" target="_blank">item.name</a>, item.start_date<br>... <br>The Stranger 2010<br>
The Dude 2010<br>
<br>I figured the below quote offers the beginning of an explanation on this page:<br>"The list object stores pointers to objects, not the actual objects
themselves."<br><a href="http://effbot.org/zone/python-list.htm">http://effbot.org/zone/python-list.htm</a><br><br>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?<br>
<br>Thanks!<br>Serdar<br>