导语:
本文主要介绍了关于Python并集是什么意思?的相关知识,希望可以帮到处于编程学习途中的小伙伴
本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。
其元素属于 A 或 B 的集合是 A 和 B 的并集。
1、概念
并集就是取所有集合的所有元素,有重复的就保留一个。这是使用符号 | 完成的。或联合方法。
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有mac版吗?12/21
- ♥ python解释器在哪里08/25
- ♥ Python导入运行模块的原理11/15
- ♥ 如何在python3中以相反的顺序输出数组?11/18
- ♥ Python可以显示中文时间吗12/12
- ♥ python是脚本语言吗?01/10
内容反馈