The __hash__() method
The built-in hash() function invokes the __hash__() method of a given object. This hash is a calculation that reduces a (potentially complex) value to a small integer value. Ideally, a hash reflects all the bits of the source value. Other hash calculations – often used for cryptographic purposes – can produce very large values.
Python includes two hash libraries. The cryptographic-quality hash functions are in hashlib. The zlib module also has two high-speed hash functions: adler32() and crc32(). For the most common cases, we don't use any of these library functions. They're only needed to hash extremely large, complex objects.
The hash() function (and the associated __hash__() method) is used to create a small integer ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access