Python hash() Function

Python Programming Training Certification


Flexible Hours

100 Assignments

Instructor Led online Training

50 LMS Access

24X7 Support

100% Skill Level

Enquire Now

4.9 out of 1000+ Ratings
Best Python Institute for Learning Python Course & Training, Live Project Training in Python with Django, Data Science and AI, Interview Assistance, Expert Coaching Trainers. Python Certification & Interview Assistance! Get free demo now!

Course Overview

Python is one of the world’s top programming languages used today and Python training has become the most popular training across individuals. Training Basket’s Python Training & Certification course covers basic and advanced Python concepts and how to apply them in real-world applications.Python is a flexible and powerful open-source language that is easy to learn and consists of powerful libraries for data analysis and manipulation. Our Python training course content is curated by experts as per the standard Industry curriculum. The curriculum, coding challenges and real-life problems cover data operations in Python, strings, conditional statements, error handling, shell scripting, web scraping and the commonly used Python web framework Django. Take this Python training and certification course and become job-ready now.

Python hash() Function

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

Signature

  • hash (object)

Parameters

object: The object of which hash, we want to get. Only immutable types can be hashed.

Return

It returns the hash value of an object.

Let’s see some examples of hash() function to understand it’s functionality.

Python hash() Function Example 1

Here, we are getting hash values of integer and float values. See the below example.

  • # Python hash() function example
    # Calling function
    result = hash(21) # integer value
    result2 = hash(22.2) # decimal value
    # Displaying result
    print(result)
    print(result2)

Output:

  • 21
    461168601842737174

Python hash() Function Example 2

This function can be applied to the iterable values to get hash values.

  • # Python hash() function example
    # Calling function
    result = hash(“javatpoint”) # string value
    result2 = hash((1,2,22)) # tuple value
    # Displaying result
    print(result)
    print(result2)

Output:

  • -3147983207067150749
    2528502973955190484

Python hash() Function Example 3

  • # Python hash() function example
    # Calling function
    result = hash(“javatpoint”) # string value
    result2 = hash([1,2,22]) # list
    # Displaying result
    print(result)
    print(result2)

Output:

  • TypeError: unhashable type: ‘list’

Python hash() Function Example 4

Here, we are passing a new custom object to the function. The function returns the hash of this object.

  • # Python hash() function example
    class Student:
    def __init__(self,name,email):
    self.name = name
    self.email = email

    student = Student(“Arun”, “arun@abc.com”)
    # Calling function
    result = hash(student) # object
    # Displaying result
    print(result)

Output:

  • 8793491452501

Recently Trained Students

Jessica Biel

– Infosys

My instructor had sound Knowledge and used to puts a lot of effort that made the course as simple and easy as possible. I was aiming for with the help of the ZebLearn Online training imparted to me by this organization.

Richard Harris

– ITC

I got my training from Zeblearn in the Python Certification Training, I would like to say that say he is one of the best trainers. He has not even trained me but also motivated me to explore more and the way he executed the project, in the end, was mind-blowing.


Candidate’s Journey During Our Training Program

Card image cap

Expert’s Advice & Selection of Module

Choosing the right type of module for the training is half the battle & Our Team of experts will help & guide you.

Card image cap

Get Trained

Get Trained & Learn End to End Implementation from our Expert Trainer who are working on the same domain.

Card image cap

Work on Projects

We Do make our student’s work on multiple case studies , scenario based tasks & projects in order to provide real-time exposure to them.

Card image cap

Placements

We have a dedicated placement cell in order to provide placement assistance & relevant interviews to our candididates till selection

Placement Partner

×

Leave your details

×

Download Course Content