小白教程
所有教程
关于
Search
172.70.100.206
172.70.100.206
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Ref set intersection update”的源代码
本页内容
上一节:
Ref_set_intersection
下一节:
Ref_set_isdisjoint
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:intersection_update()}}[[Category:python3 set|8]] = Python Set intersection_update() 方法 = [[python3 set#setmethod|Python 集合]] == 描述 == <code>intersection_update()</code> 方法用于获取两个或更多集合中都重叠的元素,即计算交集。 <code>intersection_update()</code> 方法不同于 <code>intersection()</code> 方法,因为 <code>intersection()</code> 方法是返回一个新的集合,而 <code>intersection_update()</code> 方法是在原始的集合上移除不重叠的元素。 == 语法 == intersection_update() 方法语法: <sample title="" desc="" lang="python" hererun="1"> set.intersection_update(set1, set2 ... etc) </sample> == 参数 == * set1 -- 必需,要查找相同元素的集合 * set2 -- 可选,其他要查找相同元素的集合,可以多个,多个使用逗号 , 隔开 == 返回值 == 无。 移除 x 集合中不存在于 y 集合中的元素: == 实例 1 == <sample title="" desc="" lang="python" hererun="1"> x = {"apple", "banana", "cherry"} # y 集合不包含 banana 和 cherry,被移除 y = {"google", "xiaobai", "apple"} x.intersection_update(y) print(x) </sample> 输出结果为: <sample title="" desc="" lang="python" hererun="1"> {'apple'} </sample> 计算多个集合的并集: == 实例 1 == <sample title="" desc="" lang="python" hererun="1"> x = {"a", "b", "c"} y = {"c", "d", "e"} z = {"f", "g", "c"} x.intersection_update(y, z) print(x) </sample> 输出结果为: <sample title="" desc="" lang="python" hererun="1"> {'c'} </sample> [[python3 set#setmethod|Python 集合]]
返回至“
Ref set intersection update
”。
上一节:
Ref_set_intersection
下一节:
Ref_set_isdisjoint