intersection_update() 方法用于获取两个或更多集合中都重叠的元素,即计算交集。
intersection_update() 方法不同于 intersection() 方法,因为
intersection() 方法是返回一个新的集合,而
intersection_update() 方法是在原始的集合上移除不重叠的元素。
intersection_update() 方法语法:
set.intersection_update(set1, set2 ... etc)
无。
移除 x 集合中不存在于 y 集合中的元素:
x = {"apple", "banana", "cherry"} # y 集合不包含 banana 和 cherry,被移除 
y = {"google", "dida100", "apple"}
 
x.intersection_update(y) 
 
print(x)
输出结果为:
{'apple'}
计算多个集合的并集: