How to Use hash() Function in PythonPython Basics


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.

© 2024 Cheerlearn.com, all rights reserved. Privacy Policy | Contact Us