mutate dictionary or list
Ben Finney
ben+python at benfinney.id.au
Tue Sep 7 10:46:43 EDT 2010
deets at web.de 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:
<URL:http://effbot.org/zone/python-objects.htm>
<URL:http://docs.python.org/reference/datamodel.html#objects-values-and-types>
--
\ “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