Python hash() Function26 Sept 2024 | 2 min read Python 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 |
Function The python list() creates a list in python. Signature list(iterable) Parameters iterable (optional) - An object that can be a sequence( string, tuple etc.) or collection( set, dictionary etc.) or iterator object. Return It returns a list. Function Example 1 The below example create a list from sequence: string, tuple and list. #...
1 min read
Function function is used to get remainder and quotient of two numbers. This function takes two numeric arguments and returns a tuple. Both arguments are required and numeric. This function has the following syntax. Signature divmod (number1, number2) Parameters number1: A numeric value, it is required. number2: A numeric value,...
1 min read
Function function returns the list of names in the current local scope. If the object on which method is called has a method named __dir__(), this method will be called and must return the list of attributes. It takes a single object type argument....
2 min read
Function In Python, we have a number of inbuilt functions. One such function is the function. The Python slice function is used to get a slice or a portion of elements from the collection of elements such as a list, tuple, or string. The slice function...
5 min read
Function The python getattr() function returns the value of a named attribute of an object. If it is not found, it returns the default value. Signature getattr(object, attribute, default) Parameters object: An object whose named attribute value is to be returned. attribute: Name of the attribute of which you want to...
1 min read
Function The python format() function returns a formatted representation of the given value. Signature format(value, format) Parameters value: It is the value that needs to be formatted. format: It is the specification on how the value should be formatted. Return It returns a formatted representation of the given value. Function Example 1 The...
1 min read
Function function is used to sort a sequence of elements. The sorted() function can be used to sort a variety of data structures or complex objects effortlessly in ascending or descending order. By default, it sorts elements in ascending order. The sorted function takes three arguments...
6 min read
Function The python memoryview() function returns a memoryview object of the given argument. Before we come to the memoryview, we have to understand about Python's Buffer Protocol. Buffer Protocol provides a way to access internal data of an object. This internal data is a memory array or a...
2 min read
Function The python ord() function returns an integer representing Unicode code point for the given Unicode character. Signature ord(character) Parameters character: A character string of length 1. Return It returns an integer that represents Unicode code point for the given Unicode character. Function Example 1 The below example shows the working of...
1 min read
Function Python is a flexible programming language with a vast library of functions that can make coding a lot more straightforward. Quite possibly of the most remarkable and frequently used function in Python is the eval() function. In this article, we will examine the eval() function...
3 min read
We request you to subscribe our newsletter for upcoming updates.
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