Addressing the last element of a list

Donn Cave donn at
Thu Nov 10 07:47:41 CET 2005

Quoth Steven D'Aprano <steve at>:
| So when working with ints, strs or other immutable objects, you aren't
| modifying the objects in place, you are rebinding the name to another
| object:
| py> spam = "a tasty meat-like food"
| py> alias = spam  # both names point to the same str object
| py> spam = "spam spam spam spam"  # rebinds name to new str object
| py> print spam, alias
| 'spam spam spam spam' 'a tasty meat-like food'

The semantics of assignment are like that, period.  If the right hand
side is an int, a string, a class instance, a list, whatever, doesn't
matter at all.  The question of mutability at this point can be a red
herring for someone who doesn't already understand these matters.

Mutability is nothing special, it's just a feature built into the
object type -- in general, the ability to store some state.  This
is of course useful in situations where we want to propagate state
changes, so it naturally comes up in this context, but language per
se does not observe any distinction here so far as I know.

	Donn Cave, donn at drizzle.

More information about the Python-list mailing list