python frozenset()
函数用于返回不可变的frozenset对象。它是python的内置函数。
语法
语法如下:frozenset([iterable])
参数
- iterable:可迭代对象。可迭代对象可以是集合、字典、元组等。
返回值
返回不可变的frozenset对象。
程序示例
#!/usr/bin/python
# coding=utf-8
lst = [1,2,3]
tu = ('yxjc123','baidu','sohu')
dic = {'one': 1, 'two': 2, 'three': 3}
lst_frzon = frozenset(lst)
tu_frzon = frozenset(tu)
dic_frzon = frozenset(dic)
print(lst_frzon)
print(tu_frzon)
print(dic_frzon)
程序运行结果:
frozenset({1, 2, 3})
frozenset({'sohu', 'yxjc123', 'baidu'})
frozenset({'two', 'three', 'one'})
frozenset({'sohu', 'yxjc123', 'baidu'})
frozenset({'two', 'three', 'one'})