python 集合类型
来源:互联网 发布:php构造方法怎么写 编辑:程序博客网 时间:2024/06/08 16:51
There are two types of set:variable set and immutable set:variable set can not be hashed.Note:frozenset can not be changed!
Note:we can not create a set by operator(can not treated as list ant tuple or diretoty).we can only use set() anf frozenzet().
1.create and update
> myset=set("abadsfljasd")> mysetset(['a', 'b', 'd', 'f', 'j', 'l', 's'])
Note:we can not create a set by operator(can not treated as list ant tuple or diretoty).we can only use set() anf frozenzet().
1.1visit the value in a set:
'a' in myset
1.2update a set
myset.add('z')myset.update("python")myset.remove("abcd")s-=set("python")
1.3delete a set
del myset2.the oprator of set
2.1 standard operator
in,no in,==,!= , > , >=, <, <=2.2 'set' type operator
combine: "|"> twoset=se("xyz")> oneset | twosetset(['a', 'c', 'b', 'd', 'y', 'x', 'z'])&, -, ^
>oneset ^ threeset>set(['c', 'd', '1', '3', '2'])
mixed-type operate:set and frozen set> myset=set("abcd")> myfrozenset=frozenset("1234")> myset | myfrozensetset(['a', 'c', 'b', 'd', '1', '3', '2', '4'])> myfrozenset | mysetfrozenset(['a', 'c', 'b', 'd', '1', '3', '2', '4'])Note:the result type follow the former.
2.3set-type operator---only used for set not for frozenset
Update:|=, &=, -=, ^=3.build_in function
len(), set(), frozenset()3.1 set-type build_in function
Note:build_in function means standart build_in function that could used for set .set-type build_in function means this function is part of set-type.function name return value
s.add('a') update s
s.clear() clear s
s.difference(t) a new set(element in s but not in t)
s.union(t) a new set
s.intersection(t) a new set
s.issubset(t) True or False
3.2compare: operator and build_in function:
For the most, build_in function and operarot is equal. However, the operand for the operator must be set-type, while the object for the build_in function could be iterative type. 0 0
- Python映射类型、集合类型
- python 集合类型
- 集合类型 (python)
- python集合类型方法
- python 集合类型
- Python 中的 集合类型 --- set
- python映像和集合类型
- Python基础:05集合类型
- python可变集合类型方法
- Python:映像和集合类型
- python 集合类型总结表
- Python中的集合类型(笔记)
- Python集合(set)类型的操作
- Python集合容器类型之List用法
- Python集合(set)类型的操作
- Python集合(set)类型的操作
- Python集合(set)类型的操作
- Python集合(set)类型的操作
- LayoutInflater的作用和用法(转)
- eternity65
- MySQL数据汇总与聚集函数——MySQL系列(七)
- 单击和双击事件的冲突处理
- linux shell不显示路径问题
- python 集合类型
- 完成使用CALayer创建的一个旋转的3D立方体。
- android 安卓TabActivity 两次返回键退出
- mount/umount命令详解
- Java 如何判断String为空?
- Eclipse编辑java文件报Unhandled event loop exception错误的解决办法
- Android获取已安装应用信息(图标,名称,版本号,包)
- LeetCode:Convert Sorted Array to Binary Search Tree
- android eclipse debug 调试 Source not found