[Tutor] A deeper explanation of ability to modify list elements in-place

Steven D'Aprano steve at pearwood.info
Thu Nov 11 18:41:34 CET 2010


Serdar Tumgoren wrote:

> But I think I see your point. The list object behaves the same as the
> objects stored inside the list.

Er, surely not... the list object is a list, the objects inside the list 
are ints. They do not behave the same.


 > In other words, the list object is a
> reference to an ordered sequence of object references, and you're operating
> on those (referenced) objects rather than copies of the objects when you
> iterate over the list. Is that correct? If so, no doubt there's a simpler
> way to say all that?

"A list is an ordered sequence of objects. When you iterate over the 
list, you see the contents of the list, not copies. Python never copies 
objects unless you explicitly tell it to."



-- 
Steven



More information about the Tutor mailing list