Skip to main content

hash()

The hash() function in Python is a built-in function that returns the hash value of an object. The hash value is an integer that represents the value of the object and is used in hash tables for quick lookups.

Parameter Values

Parameter Description
obj

The object which has to be hashed. It must be hashable (meaning that it has a hash value) to be used as a key in a dictionary or a set.

Return Values

The hash() function in Python returns an integer.

How to Use hash() in Python

Example 1:

The hash() method returns the hash value of an object if it has one. Hash values are integers used to quickly compare dictionary keys during a dictionary lookup. They are also used in set data structures.

hash('hello')
hash((1, 2, 3))
hash({'a': 1, 'b': 2})