是的,在Python中,set数据结构可以进行并集操作。你可以使用union()方法或者|运算符来实现两个集合的并集。
以下是使用union()方法的示例:
set1 = {1, 2, 3}
set2 = {3, 4, 5}
result = set1.union(set2)
print(result)  # 输出:{1, 2, 3, 4, 5}
以下是使用|运算符的示例:
set1 = {1, 2, 3}
set2 = {3, 4, 5}
result = set1 | set2
print(result)  # 输出:{1, 2, 3, 4, 5}
在这两个示例中,我们首先创建了两个集合set1和set2,然后使用union()方法或|运算符计算它们的并集,并将结果存储在变量result中。最后,我们打印出结果。

 便宜VPS测评
便宜VPS测评









