Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
communitycreator

What is hash() in Python?

Mahnoor Zaheer

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The hash() method returns the hash value of an object in Python.

Syntax

The syntax of this function is as follows:

hash(object)
The syntax of hash() method in Python

Parameters and return value

The hash() function takes one mandatory parameter, which is the object whose hash value is required.

The return value is an integer indicating the hash value of the specified object.

Example

In the example below, the hash() method is used to generate the has hash values of a string, integer, decimal number, and a set.

# hash value for string
print('The hash for Educative is:', hash('Educative'))
# hash value for integer
print('The hash for 470 is:', hash(181))
# hash value for decimal numbers
print('The hash for 156.2 is:',hash(181.23))
# hash value for list
print('The hash for (1,2,3) is:', hash((1,2,3)))
The syntax of hash() method in Python

RELATED TAGS

python
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring