标签:python
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#删除会报错
标签:python
原文地址:http://blog.51cto.com/11518612/2084023