Python内置函数(24)——set
英文文档:
- class
set([iterable]) - Return a new
setobject, optionally with elements taken from iterable.setis a built-in class. Seesetand Set Types — set, frozenset for documentation about this class. - For other containers see the built-in
frozenset,list,tuple, anddictclasses, as well as thecollectionsmodule.
根据传入的参数生成一个新的集合
说明:
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}

浙公网安备 33010602011771号