我尝试搜索互联网,但找不到 hashable
的含义。
当他们说对象是 hashable
或 hashable objects
是什么意思?
最佳答案
来自 Python glossary :
An object is hashable if it has a hash value which never changes during its lifetime (it needs a
__hash__()
method), and can be compared to other objects (it needs an__eq__()
or__cmp__()
method). Hashable objects which compare equal must have the same hash value.Hashability makes an object usable as a dictionary key and a set member, because these data structures use the hash value internally.
All of Python’s immutable built-in objects are hashable, while no mutable containers (such as lists or dictionaries) are. Objects which are instances of user-defined classes are hashable by default; they all compare unequal, and their hash value is their
id()
.
关于python - "hashable"在 Python 中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14535730/
相关文章:
python - 如何将 SqlAlchemy 结果序列化为 JSON?
python - pip 安装 : Please check the permissions and
python - 导入错误 : No module named PIL
python - 在python中跳过for循环的第一个条目?
linux - 带有 -i 选项的 sed 命令(就地编辑)在 Ubuntu 上运行良好,但在 Ma
python - glob.glob() 的返回值是如何排序的?
linux - Linux Bash 中的双与号 (&&) 和分号 (;) 有什么区别?