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}
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}
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。