* 作者:煮酒品茶 tea
* 博客:http://www.zwhset.com http://cwtea.blog.51cto.com
* 目前在京峰教育担任python讲师
# 0、不可变集合frozenset
> frozenset是不可变的集合, 简单说就是不能修改的set集合, 它和set集合类似,区别在于一个可变, 另一个不可变,其它的功能一样。 很像list和tuple的区别
# 1、函数原型
~~~
frozenset() -> empty frozenset object # 创建空的 frozense集合
frozenset(iterable) -> frozenset object # 从一个iterable转换成frozense集合
difference(...)
Return the difference of two or more sets as a new set.
(i.e. all elements that are in this set but not the others.)
intersection(...)
Return the intersection of two or more sets as a new set.
(i.e. elements that are common to all of the sets.)
isdisjoint(...)
Return True if two sets have a null intersection.
issubset(...) # 子集判断
Report whether another set contains this set.
issuperset(...) # 父集判断
Report whether this set contains another set.
symmetric_difference(...)
Return the symmetric difference of two sets as a new set.
(i.e. all elements that are in exactly one of the sets.)
union(...) # 并集
Return the union of sets as a new set.
~~~
# 2、样例
~~~
>>> frozen_set = frozenset() # 创建一个空的frozenset集合
>>> frozen_set
frozenset([])
>>>
>>> frozen_set2 = frozenset('abcdefghigkomnopqrszuvwxyz') # 从一个str创建一个frozenset集合
>>> frozen_set2
frozenset(['a', 'c', 'b', 'e', 'd', 'g', 'f', 'i', 'h', 'k', 'm', 'o', 'n', 'q', 'p', 's', 'r', 'u', 'w', 'v', 'y', 'x', 'z'])
>>>
>>> frozen_set2 = frozenset(['a','b','c','d','e']) # 从一个list创建一个frozenset集合
>>> frozen_set2
frozenset(['a', 'c', 'b', 'e', 'd'])
~~~
# 3、应用场景:
如果要创建和使用一个不会修改的集合可以用frozenset, 能用不可变的对就用不可变的对象
- python核心
- python27编译安装
- 原处修改以及拷贝
- loop
- 内置的变量
- 内置类型
- python内置方法
- 内置方法列表
- 求绝对值-abs
- 求商取余-divmod
- 交换输入-input
- [未完]文件打开函数-open
- staticmethod
- 判断迭代对象真假all
- 判断迭代对象真假any
- 枚举对象enumerate
- 整数转换类型int
- ascii码转换ord-chr-unichr
- 类型转换str
- python执行字符串表达式eval
- 类型判断isinstance
- 数学计算pow
- 数学计算和sum
- 不可变集合frozenset
- zip
- 比较cmp
- basestring类型判断
- 反转序列迭代器resversed
- python模块
- glob
- sys.argvgetopt-argparse
- os
- sys
- requests
- random
- time
- date
- zlib-gzip-bz2-zipfile-tarfile
- ftp
- paramiko
- pexpect
- 数据库模块
- redis
- mysql
- mongodb
- __builtin__
- 学生PYTHON分享
- 学生运维分享