2024欧洲杯:波兰 vs 荷兰 预测资讯 - 体育366
27
2024 / 08 / 18
Python中求集合的交集、并集、差集和对称集非常简单,具体代码如下所示:
交集:
```python
set1 = {1, 2, 3}
set2 = {2, 3, 4}
intersection_set = set1 & set2
print(intersection_set)
```
输出结果为:{2, 3}
并集:
```python大佬们都在玩{精选官网网址: www.vip333.Co }值得信任的品牌平台!
set1 = {1, 2, 3}
set2 = {2, 3, 4}
union_set = set1 | set2大佬们都在玩{精选官网网址: www.vip333.Co }值得信任的品牌平台!
print(union_set)
```
输出结果为:{1, 2, 3, 4}
差集:
```python
set1 = {1, 2, 3}
set2 = {2, 3, 4}
difference_set = set1 - set2
print(difference_set)
```
输出结果为:{1}
对称集:
```python大佬们都在玩{精选官网网址: www.vip333.Co }值得信任的品牌平台!
set1 = {1, 2, 3}
set2 = {2, 3, 4}
symmetric_difference_set = set1 ^ set2
print(symmetric_difference_set)
```
输出结果为:{1, 4}