A hash function is any function that can be used to map data of arbitrary size to fixed-size values. The values returned by a hash function are called hash values, hash codes, digests, or simply hashes. The values are usually used to index a fixed-size table called a hash table.
Hash functions are cryptographic functions that take in an arbitrary amount of data input and produce a fixed-size output of enciphered text called a hash value, or just “hash.”
Hashing differs from encryption in the sense that while encryption creates an indecipherable object from the plain text that can be decrypted from algorithms and a key, hashing is a one-way process. This means that once created, the original object cannot be retracted from the hash.
Python has a built-in hash()
function that returns the hash value of an object. This makes creating the hash of an object quite simple in Python.
The Python
hash
function can be run on specific data types such as bool, int, long, float, string, Unicode, or tuple, but not on lists, sets, dictionaries, or byte arrays.
>>> hash(object)
## returns the hash value of the object
print(hash('this is an object'))print(hash(('python','hash','function',1)))#hash([1,2,3,4]) #It doesnt work for lists. Will throw a TypeError