Python 3 教程
intersection_update() 方法用于獲取兩個或更多集合中都重疊的元素,即計算交集。
intersection_update()
方法不同于 intersection()
方法,因為
intersection()
方法是返回一個新的集合,而
intersection_update()
方法是在原始的集合上移除不重疊的元素。
intersection_update() 方法語法:
set.intersection_update(set1, set2 ... etc)
無。
返回一個新集合,該集合的元素既包含在集合 x 又包含在集合 y 中:
輸出結(jié)果為:
{'apple'}
計算多個集合的并集:
輸出結(jié)果為:
{'c'}