1. 使用交集操作符 `&`:
```python
set1 = {1, 2, 3}
set2 = {2, 3, 4}
intersection_set = set1 & set2
print(intersection_set) 输出:{2, 3}
2. 使用 `intersection()` 方法:
```python
set1 = {1, 2, 3}
set2 = {2, 3, 4}
intersection_set = set1.intersection(set2)
print(intersection_set) 输出:{2, 3}
以上两种方法都可以用来计算两个集合的交集。如果有多个集合需要求交集,可以继续使用 `&` 操作符或 `intersection()` 方法:
```python
set1 = {1, 2, 3}
set2 = {2, 3, 4}
set3 = {3, 4, 5}
intersection_set = set1 & set2 & set3
print(intersection_set) 输出:{3}
或者
```python
intersection_set = set1.intersection(set2, set3)
print(intersection_set) 输出:{3}