Python hash() FunctionPython has() function is used to get the hash value of an object. Python calculates the hash value by using the hash algorithm. The hash values are integers an used to compare dictionary keys during a dictionary lookup. We can hash only these types: Hashable types: * bool * int * long * float * string * Unicode * tuple * code object We cannot hash of these types: Non-hashable types: * bytearray * list * set * dictionary * memoryview SignatureParametersobject: The object of which hash, we want to get. Only immutable types can be hashed. ReturnIt returns the hash value of an object. Let's see some examples of hash() function to understand it's functionality. Python hash() Function Example 1Here, we are getting hash values of integer and float values. See the below example. Output: 21 461168601842737174 Python hash() Function Example 2This function can be applied to the iterable values to get hash values. Output: -3147983207067150749 2528502973955190484 Python hash() Function Example 3Output: TypeError: unhashable type: 'list' Python hash() Function Example 4Here, we are passing a new custom object to the function. The function returns the hash of this object. Output: 8793491452501 Next TopicPython Functions |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India