[Tutor] hash
Andreas Kostyrka
andreas at kostyrka.org
Thu Jul 5 00:26:16 CEST 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Simple, defining __hash__ on a class allows you to supply a hash value
for instances of your class.
andreas at andi-lap:~> cat /tmp/hash.py
class X:
def __hash__(self):
print "HASH CALLED"
return 123
print hash(X())
andreas at andi-lap:~> python /tmp/hash.py
HASH CALLED
123
Andreas
linda.s wrote:
> what is the use of def __hash__(self)?
> I can not understand the document.
> any example? thanks,
> Linda
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFGjB6IHJdudm4KnO0RAskJAKC4WZHo1Kv6MrHOzSWULOgMa+pDsgCgznRy
Thwd2n1BgWjW8OEDUIILHXY=
=y2W0
-----END PGP SIGNATURE-----
More information about the Tutor
mailing list