首页 › 参考手册 › 集合方法 › set.union()

Python set.union() 方法

描述

返回并集,等价于 | 运算符。

语法

set.union(*others)

参数

参数说明
others其他集合或可迭代对象

返回值

新集合

实例

a, b = {1, 2}, {2, 3}
print(a.union(b), a | b)
print(a.union([9], (8,)))
以上实例输出结果为:
{1, 2, 3} {1, 2, 3}
{8, 1, 2, 9}