set

set 集合;

a = [1,2,3,4,5]
b = [4,5,6,7,8]
#intersection()交集;interc ;符號&
print(a.interction(b))
[4,5]
#union;聯合;並集;符號|
print(a.union(b))
[1,2,3,4,5,6,7,8]
#差集;符號-
print(a.diference(b))
[12]#in a but not in b
print(b.diference(a))
[6,7,8]in b but not in a
#反向交集symmetric _difference;符號: ^
print(a.symmetric_differenec(b))
[4,5]

父集和子集;(包含的)
print(a.issuperset(b))
print(a.issubset(b))
a = [1,2,3,'alex']
s = set(a)
s.pop()#隨機刪
s.add()
s.remove()#刪除指定
s.update()
s.clear()#清空
delete s#刪除會報錯
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章