mutate dictionary or list

Ben Finney ben+python at
Tue Sep 7 16:46:43 CEST 2010

deets at writes:

> Objects can be mutable or immutable. For example, in Python, integers,
> strings, floats and tuples are immutable. That means that you can't
> change their value.

Yes. Importantly, wherever you see code that you *think* is changing the
value of an immutable object, you're thinking incorrectly. (There's no
shame in that; other languages give us preconceptions that can be hard
to shake off.)

The only way to get a different value from an integer object is to ask
Python for a different integer object; the original is unchanged. The
same goes for tuples, strings, and all the other immutable types.

> Mutable objects OTOH can be changed.

Some good articles to explain Python's object model:


 \             “We can't depend for the long run on distinguishing one |
  `\         bitstream from another in order to figure out which rules |
_o__)               apply.” —Eben Moglen, _Anarchism Triumphant_, 1999 |
Ben Finney

More information about the Python-list mailing list