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#删除会报错
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章