Python内置函数(56)——set

英文文档:

class set([iterable])
Return a new set object, optionally with elements taken from iterable. set is a built-in class. See set and Set Types — set, frozenset for documentation about this class.
For other containers see the built-in frozenset, list, tuple, and dict classes, as well as the collections 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}

 

posted @ 2016-11-14 22:52  十月狐狸  阅读(1215)  评论(0编辑  收藏  举报