hashable
Glossary — Python 3.6.5 documentation https://docs.python.org/3/glossary.html?highlight=equal
hashable
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__()
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; mutable containers (such as lists or dictionaries) are not. Objects which are instances of user-defined classes are hashable by default. They all compare unequal (except with themselves), and their hash value is derived from their id()
.
不变性对象可以哈希化,可变容器:list、dict不可哈希化
可哈希化的仅仅和自己equal,
immutable 不可变性
An object with a fixed value. Immutable objects include numbers, strings and tuples. Such an object cannot be altered. A new object has to be created if a different value has to be stored. They play an important role in places where a constant hash value is needed, for example as a key in a dictionary.
hashable的更多相关文章
- 实习小记-python中可哈希对象是个啥?what is hashable object in python?
废话不多说直接祭上python3.3x的文档:(原文链接) object.__hash__(self) Called by built-in function hash() and for opera ...
- Swift自定义Class实现Hashable
假如有个Bit类,其中含有CGPoint类型的point属性,Class定义如下 class Bit { var point : CGPoint init(point : CGPoint) { sel ...
- 【转】实习小记-python中可哈希对象是个啥?what is hashable object in python?
[转]实习小记-python中可哈希对象是个啥?what is hashable object in python? 废话不多说直接祭上python3.3x的文档:(原文链接) object.__ha ...
- 什么是可哈希的(hashable)
如果一个对象在自己的生命周期中有一哈希值(hash value)是不可改变的,那么它就是可哈希的(hashable)的,因为这些数据结构内置了哈希值,每个可哈希的对象都内置了__hash__方法,所以 ...
- python hashable
判断一个对象是否hashable: hash(obj) 或 obj.__hash__() ,返回 hash 值 hashable 的有: int / float / tuple / str/ obj ...
- hashable/iterable与orderable
################ # hashable协议 # ################ # 一个对象能被称为hashable,它必须实现__hash__与_eq__方法: >>& ...
- swift的Hashable
Conforming to the Hashable Protocol To use your own custom type in a set or as the key type of a dic ...
- Python学习笔记 | 关于python数据对象 hashable & unhashable 的理解
文章目录 写在前面 hashable & unhashable mutable & immutable 实例检测 后续思考 参考文章 写在前面 Hash(哈希.散列)是一个将大体量数据 ...
- [python数据结构] hashable, list, tuple, set, frozenset
学习 cs212 unit4 时遇到了 tuple, list, set 同时使用的问题,并且进行了拼接.合并操作.于是我就被弄混了.所以在这里进行一下总结. hashable and unhasha ...
- hashable与unhashable
不可哈希(unhashable):就是指其可变,如列表.字典等,都能原地进行修改. 可哈希(hashable):不可变,如字符串.元组那样,不能原地修改. 利用set()和{}建立集合时,要求集合中的 ...
随机推荐
- Java集合之Queue
queue 定义 C++:queue Java:Queue 创建与其基本操作 创建: Queue<Integer> q=new LinkedList<Integer>(); 数 ...
- 【HIHOCODER 1039】 字符消除
链接 问题描述 小Hi最近在玩一个字符消除游戏.给定一个只包含大写字母"ABC"的字符串s,消除过程是如下进行的: 1)如果s包含长度超过1的由相同字母组成的子串,那么这些子串会被 ...
- Ducci Sequence解题报告
A Ducci sequence is a sequence of n-tuples of integers. Given an n-tuple of integers (a1, a2, ... , ...
- 用cpp写对拍程序
#include <bits/stdc++.h> using namespace std; int main() { while(true) { puts(""); p ...
- tiles介绍
主要目的是为了将复数的jsp页面作为一个的页面的部分机能,然后用来组合成一个最终表示用页面用的,这样的话,便于对页面的各个机能的变更及维护. Tiles使得struts在页面的处理方面多了一种选择.并 ...
- ubuntu修改apt-get源为国内镜像源
1.原文件备份 sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak 2.编辑源列表文件 sudo vim /etc/apt/so ...
- RF新手常见问题总结--(基础篇)
1. 经常有人问这个元素找不到,一般先排除这两个地方,再自己找找A:是否等待了足够的时间让元素加载 (增加sleep xx, wait Until xxx)B: 仔细查查,这个元素是否进入到另一个f ...
- navicat不同数据库数据传输
复制fo的t_fo_account表结构和数据到base库 结果
- python018 Python3 输入和输出
Python3 输入和输出在前面几个章节中,我们其实已经接触了 Python 的输入输出的功能.本章节我们将具体介绍 Python 的输入输出. 输出格式美化Python两种输出值的方式: 表达式语句 ...
- Laya 类列表加载优化
Laya 类列表加载优化 @author ixenos 类列表:在一个页面展示的大量的零散单元的集合(聊天面板.背包) 一.按展示优化1.展示内容少,即使大量数据,但用户只看到少量信息的时候,考虑按需 ...