在Python中,表示集合的并集可以使用竖线符号 `|`。例如,如果你有两个集合 `set1` 和 `set2`,你可以通过以下方式计算它们的并集:
set1 = {1, 2, 3}
set2 = {3, 4, 5}
union_set = set1 | set2
print(union_set) 输出:{1, 2, 3, 4, 5}
或者使用 `union()` 方法:
set1 = {1, 2, 3}
set2 = {3, 4, 5}
union_set = set1.union(set2)
print(union_set) 输出:{1, 2, 3, 4, 5}
如果你想在键盘上直接打出并集符号 `∪`,你可以按住 `Alt` 键不放,然后在小键盘上输入 `0229`