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
How do I check if a list is empty?
For example, if passed the following:
a = [] if not a: print("List is empty")
Ref: https://bit.ly/2A4JXx9
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework