python中集合的几种运算方式

python中集合的几种运算方式

set01 = {1,2,3,4,5}
set02 = {1,2,3,6}

#&取两个集合都有的
print(set01&set02)
#{1, 2, 3}

#|并集组成新组合
print(set01|set02)
#{1, 2, 3, 4, 5, 6}

#^对称差集
print(set01^set02)
#{4, 5, 6}

#一般差集(set02中有,set01中没有的)
print(set02-set01)
#{6}
原文地址:https://www.cnblogs.com/lvye001/p/14661223.html