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
Python: Tips of the Day
Executes the provided function once for each list element:
Example:
def tips_for_each(itr, fn): for el in itr: fn(el) tips_for_each([3, 6, 9], print)
Output:
3 6 9
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook