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}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章