Python frozenset

来源:互联网 发布:淘宝app确认订单页面 编辑:程序博客网 时间:2024/06/13 13:43

用法:frozenset([iterable])

定义:返回一个冻结的集合,冻结后的集合不能添加或删除函数

示例:

>>> list = ['a','b','c','d','e','f','a','b','c'] >>> print(len(list),list)9 ['a', 'b', 'c', 'd', 'e', 'f', 'a', 'b', 'c']>>> set = frozenset(list)>>> print(len(set),set)6 frozenset({'a', 'b', 'c', 'e', 'd', 'f'})>>> set.add('g')Traceback (most recent call last):  File "<stdin>", line 1, in <module>AttributeError: 'frozenset' object has no attribute 'add'

原创粉丝点击