Python:如何使用集合intersection_update方法

 时间:2024-10-08 20:32:46

Python是常用的一种编程语言,内置了丰富的编程模块和函数。其中水貔藻疽,集合的intersection_update()方法可溅局柑氍以删除各集合中都不存在的项目。今天教大家如何在Python编程中使用集合的intersection_update()方法。

工具/原料

联想小新pro13

Win10

Python3.6.5

PyCharm2019.3.3

方法/步骤

1、首先在PyCharm软件中,打开一个Python项目。

Python:如何使用集合intersection_update方法

2、在Python项目中,新建并打开一个空白的python文件(比如:test.py)。

Python:如何使用集合intersection_update方法

3、在python文件编辑区中,使用大括号定义一个“x”集合对象。

Python:如何使用集合intersection_update方法

4、然后再使用大括号定义一个“y”集合对象。

Python:如何使用集合intersection_update方法

5、继续输入:“x.intersection_update(y)”,点击Enter键。

Python:如何使用集合intersection_update方法

6、再次输入:“print(x)”进行打印。

Python:如何使用集合intersection_update方法

7、在编辑区域点击鼠标右键,在弹出菜单中选择“运行”选项。

Python:如何使用集合intersection_update方法

8、在运行结果窗口中,已经使用Python集合的intersection_update猾诮沓靥()方法删除集合x和集合y都不存在的项目。

Python:如何使用集合intersection_update方法

《董小姐》吉他谱-尤克里里谱TXT word怎么表格排版对齐 英雄联盟之中蛮王对线大虫子怎么玩 PaperAsk查重系统如何使用自动降重?
热门搜索
国模双人拍炮人体图片 好看的手机图片 晚娘电影 名酒图片 爱护环境的图片