mutate dictionary or list

Baba raoulbia at gmail.com
Wed Sep 8 12:04:24 CEST 2010


On 7 sep, 16:46, Ben Finney <ben+pyt... at benfinney.id.au> wrote:
> de... 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

Thanks all for feedback!
Baba



More information about the Python-list mailing list