
intersection_update()使用集的交集更新调用intersection_update()方法的集。
两个或更多集合的交集是所有集合共有的元素集合。
要了解更多信息,请访问Python set Intersection。
junction_update()的语法为:
A.intersection_update(*other_sets)
intersection_update()参数
intersection_update()允许任意数量的参数(集合)。
注意: *不是语法的一部分。用于指示该方法允许任意数量的参数。
Intersection_update()返回值
此方法返回None(意味着,没有返回值)。它仅更新调用intersection_update()方法的集合。
假设,
result = A.intersection_update(B, C)
当您运行代码时,
- result 将为 None 
- A 等于A B和C的交点 
- B 保持不变 
- C 保持不变 
示例1:如何使用intersection_update()?
A = {1, 2, 3, 4}
B = {2, 3, 4, 5}
result = A.intersection_update(B)
print('result =', result)
print('A =', A)
print('B =', B)运行该程序时,输出为:
result = None
A = {2, 3, 4}
B = {2, 3, 4, 5, 6}示例2:具有两个参数的intersection_update()
A = {1, 2, 3, 4}
B = {2, 3, 4, 5, 6}
C = {4, 5, 6, 9, 10}
result = C.intersection_update(B, A)
print('result =', result)
print('C =', C)
print('B =', B)
print('A =', A)运行该程序时,输出为:
result = None
C = {4}
B = {2, 3, 4, 5, 6}
A = {1, 2, 3, 4}
                    
                