英文文檔: 說明: 1. 傳入一個可迭代對象,生成一個新的集合。 2. 不傳入參數時,生成一個新的空集合。 3. 返回的集合是可以修改的。 ...
英文文檔:
- class
set
([iterable]) - Return a new
set
object, optionally with elements taken from iterable.set
is a built-in class. Seeset
and Set Types — set, frozenset for documentation about this class. - For other containers see the built-in
frozenset
,list
,tuple
, anddict
classes, as well as thecollections
module.
說明:
1. 傳入一個可迭代對象,生成一個新的集合。
>>> a = set(range(10)) >>> a {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
2. 不傳入參數時,生成一個新的空集合。
>>> a = set() >>> a set()
3. 返回的集合是可以修改的。
>>> a = set() >>> a set() >>> a.add(1) >>> a {1}