hash

Full name
hash
Library
Built-in
Syntax

hash(object)

Description

The hash function returns the hash value of the object passed as a argument -if any-. Hash values are integers. Numeric values that, when compared, return True have the same associated hash value, even if they are of different type.

Result

The hash function returns an integer.

Examples

The hash value of any number with no decimal part (be it integer, real, or complex) matches the number itself (interpreted as an integer). The booleans True and False values are interpreted as 1 and 0, respectively:

Hash function. Example of use

 

The hash of a couple of text strings is calculated in this example:

Hash function. Example of use

 

The tuples have a hash value associated with them. In contrast, a mutable object like a list doesn't:

Hash function. Example of use

 

Submitted by admin on Fri, 01/25/2019 - 16:45