【Python】set与frozenset的区别
来源:互联网 发布:数据库镜像 数据库备份 编辑:程序博客网 时间:2024/04/28 06:51
同多数语言一样,set表示集合,最重要的特性就是无序,所以Python中的set不支持indexing,但支持len(set),x in set 等操作。
set有两种类型,set和frozenset。
set是可变的,有add(),remove()等方法。既然是可变的,所以它不存在哈希值。
frozenset是冻结的集合,它是不可变的,存在哈希值,好处是它可以作为字典的key,也可以作为其它集合的元素。缺点是一旦创建便不能更改,没有add,remove方法。
举例如下
fza=frozenset('a')adict={fza:1,'b':2} #正确setb=set('a')bdict={setb:1,'b':2} #错误
还有一点需要注意,不管是set还是frozenset,Python都不支持创建一个整数的集合。
seta=set(1) #错误setb=set('1')#正确
0 0
- 【Python】set与frozenset的区别
- 【Python】set与frozenset的区别
- Python集合set与frozenset的区别
- 【Python】set与frozenset的区别
- 【Python】set与frozenset的区别
- python中set与frozenset区别整合
- Python 中的 set 与 frozenset
- python中frozenset( )和set()的用法区别
- python: set frozenset
- python:set和frozenset
- 【Python】set和frozenset
- python中set和frozenset方法和区别
- python中set和frozenset方法和区别
- python中set和frozenset方法和区别
- Python中的集合:set与frozenset用法举例
- Python中的集合:set与frozenset用法举例
- python中set和frozenset详解
- python中set(可变集合)、frozenset(不可变集合)的基本操作
- 影响子查询展开的情况
- php解析xml
- Uart debug before console ready low level debug
- Effective stl 第一章 第7、8条
- 【整理】adb命令、adb shell与Linux各种命令(busybox)
- 【Python】set与frozenset的区别
- java设计模式(4)---多例模式
- 图片文字识别
- Java正则表达式
- Jos-lab2 (Challenges)
- unity修改网格数据
- Android对Linux内核的改动?
- Linux驱动子系统之I2C(4)
- 测试用例注意