python-数据类型:集合set
set:本身非可哈希,但set里面元素必须可哈希
非可哈希不能作为字典的键
#set更新: s.add('asdf') s.update('asdf') s.remove('a') s.pop()#随机删除 s.clear()#清空s中元素,集合s还保留 del s#删除集合s,什么都不保留 a = set([1,2,3,4,5]) b = set([4,5,6,7,8]) a.intersection(b) #a和b的交集元素 a.union(b) #a和b的并集元素 a|b a.difference(b)#差集 in a but not in b a.symmetric_difference(b)#对称差集/反向交集 not in (a.intersection(b)) a.issuperset(b) a.issubset(b)