Manual
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.
直译
返回一个新的set对象,可以从iterable获取元素。set是内建类,详情见集合类型—set、frozenset
对于其他容器类,可参考内建frozenset、list、tuple和dict类,以及collections模块
实例
>>> set([i for i in range(20)])
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}
>>> a = ['Tom', 'Jack', 'Rose', 'Tom']
>>> set(a)
{'Tom', 'Jack', 'Rose'}
>>> for i in set(a):
print(i)
Tom
Jack
Rose