当前位置: 首页 > 图灵资讯 > 行业资讯> Python并集是什么意思?

Python并集是什么意思?

发布时间:2024-08-27 13:48:05

本文教程操作环境:windows7系统Python 3.9.1,DELL G3电脑。

以属于A或属于B的元素为元素的集合成为A和B的并集。

1、概念

并集是取所有集合的元素,如果重复保留一个。使用符号 | 或者 union 方法完成。

2、实例

my_set1={"apple","orange","pear","banana","food"}
my_set2={"apple","orange","pear"}

both=my_set1|my_set2
print(both)
使用union完成。
my_set1={"apple","orange","pear","banana","food"}
my_set2={"apple","orange","pear"}

both=my_set1.union(my_set2)
print(both)

以上是Python对称差集的介绍,希望对大家有所帮助。更多Python学习指导:python基础教程

相关文章

如何让vim支持python3

如何让vim支持python3

2025-09-12
python2.7和3.6区别有哪些

python2.7和3.6区别有哪些

2025-09-12
python3有serial库吗

python3有serial库吗

2025-09-12
python中w、r表示什么意思

python中w、r表示什么意思

2025-09-12
python中如何把list变成字符串

python中如何把list变成字符串

2025-09-12
python命名空间是什么

python命名空间是什么

2025-09-12