Python సమూహం intersection_update() పద్ధతి

实例

సమూహం x మరియు సమూహం y లో ఉన్న ప్రతిపాదనలను తొలగించండి:

x = {"అపల్", "బానానా", "చెర్రీ"}
y = {"google", "microsoft", "apple"}
x.intersection_update(y) 
print(x)

运行实例

定义和用法

intersection_update() 方法会删除各集合中都不存在的项目。

intersection_update() 方法与 intersection() 方法不同,因为 intersection() 方法返回一个新集合,其中没有不需要的项目,而 intersection_update() 方法从原始集中删除了不需要的项目。

语法

set.intersection_update(set1, set2 ... etc)

参数值

参数 描述
set1 必需。要在其中检索相等项目的集合。
set2

可选。要在其中检索相等项目的另一集合。

您能够比较任意多的集合。

集合由逗号分隔。

更多实例

实例

比较 3 个集合,返回的集合包含存在于所有 3 个集合中的项目:

x = {"a", "b", "c"}
y = {"c", "d", "e"}
z = {"f", "g", "c"}
x.intersection_update(y, z)
print(x)

运行实例