What does “hashable” mean in Python?

后端 未结 9 895
挽巷
挽巷 2020-11-22 16:45

I tried searching internet but could not find the meaning of hashable.

When they say objects are hashable or hashable objects what does it

9条回答
  •  情书的邮戳
    2020-11-22 17:42

    In Python, any immutable object (such as an integer, boolean, string, tuple) is hashable, meaning its value does not change during its lifetime. This allows Python to create a unique hash value to identify it, which can be used by dictionaries to track unique keys and sets to track unique values.

    This is why Python requires us to use immutable datatypes for the keys in a dictionary.

提交回复
热议问题