语法
set 语法:
class set([iterable])
参数说明:
iterable – 可迭代对象对象;
返回值
返回新的集合对象。
实例
以下实例展示了 set 的使用方法:
x = set('runoob') y = set('google')print(x)print(y) a = x & y # 交集print(a) b = x | y # 并集print(b) c = x - y # 差集print(c)
输出:
{'n', 'r', 'u', 'b', 'o'}{'l', 'e', 'g', 'o'}{'o'}{'g', 'r', 'e', 'b', 'l', 'n', 'u', 'o'}{'n', 'r', 'u', 'b'}
相关推荐:
set()类的使用介绍
以上就是python中set()函数详解的详细内容。
