Python hash() FunctionPython Functions


The hash() function returns the hash value of an object (string or numeric value, etc.).

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-


print("the hash value of a is:  ", hash(1))

print("the hash value of a is:  ", hash(2))

print("the hash value of a is:  ", hash("A"))

print("the hash value of a is:  ", hash("a"))

Output:

the hash value of a is:   1
the hash value of a is:   2
the hash value of a is:   -4936030324487261080
the hash value of a is:   2031890805533414321

Syntax

hash(object)

Parameters

Name Description
object A string or number.

Return Value

It returns the hash value of the object.

© 2021 Programtips.org, all rights reserved. Privacy Policy | Contact Us