Python frozenset() 函數

Python 內置函數 Python 內置函數


描述

frozenset() 返回一個凍結的集合,凍結後集合不能再添加或刪除任何元素。

語法

frozenset() 函數語法:

class frozenset([iterable])

參數

  • iterable -- 可迭代的對象,比如列表、字典、元組等等。

返回值

返回新的 frozenset 對象,如果不提供任何參數,默認會生成空集合。

實例

以下實例展示了 frozenset() 的使用方法:

>>>a = frozenset(range(10)) # 生成一個新的不可變集合 >>> a frozenset([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> b = frozenset('zaixian') >>> b frozenset(['b', 'r', 'u', 'o', 'n']) # 創建不可變集合 >>>

Python 內置函數 Python 內置函數