why are some types immutable?

Dan Bishop danb_83 at yahoo.com
Sun Jan 16 18:33:59 CET 2005


Roy Smith wrote:
> Torsten Mohr <tmohr at s.netic.de> wrote:
> > reading the documentation (and also from a hint from this NG)
> > i know now that there are some types that are not mutable.
> >
> > But why is it this way?
> >
> > From an overhead point of view i think it is not optimal,
> > for example for a large string it could be much faster to
> > have it changed in place, not generating a new one for
> > every step in a change.
>
> There has been a huge amount written about immutable types recently.
A
> search of the Google news archives should turn up tons of articles.
>
> But, in a nutshell, the biggest reason for immutable types (tuples
and
> strings) is that this lets they be dictionary keys.  If you want to
know
> why dictionary keys have to be immutable,

More precisely, dictionary keys can't be mutable in any way that
affects the result of the hash function or the == or != operators.




More information about the Python-list mailing list