Python: hash() function
hash() function
The hash() function returns the hash value of the object (if it has one).
Hash values are integers. They are used to quickly compare dictionary keys during a dictionary lookup. Numeric values that compare equal have the same hash value (even if they are of different types, as is the case for 1 and 1.0).
Version:
(Python 3.2.5)
Syntax:
hash(object)
Parameter:
Name | Description | Required / Optional |
---|---|---|
object | An object. | Required. |
Example: Python hash() function
# hash for integer unchanged
print('Hash for 252 is:', hash(252))
# hash for decimal
print('Hash for 252.25 is:',hash(252.25))
# hash for string
print('Hash for Python is:', hash('Python Example'))
Output:
Hash for 252 is: 252 Hash for 252.25 is: 576460752303423740 Hash for Python is: 4427590093227766552
Python Code Editor:
Previous: globals()
Next: help()
Test your Python skills with w3resource's quiz
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/python/built-in-function/hash.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics