Unexpected result for list operator "+="

Greg Jorgensen gregj at pobox.com
Thu Jan 4 18:16:47 EST 2001


Thanks to Fredrik, Alex, Tim, and Thomas for pointing out that Python only
binds names to objects under the hood. I was guessing (maybe wrongly) that
the original poster might not know about mutable and immutable objects,
bindings, etc. That's why I wrote "Assignment of immutable objects
essentially makes a copy of the object." I lifted the explanation almost
verbatim from Beazley's "Python Essential Reference," page 19. Beazley wrote
"... effectively creates a copy..." but it amounts to the same thing--a
simplification. The real distinction--that assignment operations on
immutable objects create new objects (or bind a reference to a different
existing object)--is important but perhaps more information than necessary
to answer the question.

I appreciate the clarifications and detailed implementation info.

--
Greg Jorgensen
PDXperts
Portland, Oregon, USA
gregj at pobox.com






More information about the Python-list mailing list