confusing doc: mutable and hashable

Terry Reedy tjreedy at udel.edu
Sat Apr 28 22:06:44 EDT 2012


On 4/28/2012 2:09 PM, laymanzheng at gmail.com wrote:

> In my understanding, there is no directly relation between mutable
> and hashable in Python. Any class with __hash__ function is
> "hashable".
>
> According the wiki: http://en.wikipedia.org/wiki/Immutable_object
>
> In object-oriented and functional programming, an immutable object is
> an object whose state cannot be modified after it is created.[1] This
> is in contrast to a mutable object, which can be modified after it is
> created.
>
> We surely can define __hash__ function in user-define class and the
> instance of that class can be changed thus mutable.

The default hash is based on the immutable value of an object. If you 
base a custom hash on values that do change, it is not useful as a dict key.

-- 
Terry Jan Reedy




More information about the Python-list mailing list