60-python基础-python3-集合-集合常用方法-交集、并集、差集、对称差集-intersection(&)-union(|)-difference(-)-symmetric_difference()
交集、并集、差集-intersection(&)-union(|)-difference(-)
1-intersection(&)
s1.intersection(s2),返回s1和s2中相同部分,等价的运算符为 &.
2-union(|)
s1.union(s2) :返回一个新集合,新集合包含s1,s2的所有元素,等价的运算符为 | 。
3-difference(-)
s1.difference(s2):返回的集合为s1中去除含有的s2中的元素,等价的运算符为 -。
4-symmetric_difference()
s1.symmetric_difference(s2),返回两个集合中不重复的元素集合,即会移除两个集合中都存在的元素.