0

I was reading about hashable in Python and got the idea that in python a hashable obj must have hash and eq method defined. That makes sense to me as of now and I am learning more about it.

But in between, one thing going in my mind is when I did dir(mutable_obj) I see that they also having eq and hash method present. My expectation was it should not have hash method defined.

Example : ''' python i_list = [1,2,3,4,5] dir(i_list) ''' It gives me below output

['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'count', 'index']
Prashant Pathak
  • 173
  • 1
  • 2
  • 12
  • Does this answer your question? [What is the default \_\_hash\_\_ in python?](https://stackoverflow.com/questions/11324271/what-is-the-default-hash-in-python) – ggorlen May 10 '20 at 15:44
  • The Default __hash__ which is mentioned in the link provided is for user-defined classes, but I want to understand why we have __hash__ method present in the list, set object when I do dir(mutable_obj). What is the use of __hash__ in this object? – Prashant Pathak May 10 '20 at 18:27

0 Answers0