集合(无序不重复)
创建
s = {}
s = set()
转换
s = set(li)
方法
s.add("chy") #添加元素 s.clear() #清除元素 a = s.difference(b) #在s中找在b中不存在的元素拿来返回 s.difference_update(b) #在s中去掉在b中不存在的元素 s.discard(123) #移除指定元素,不存在不报错 s.remove(123) #移除指定元素,不存在会报错 s.intersection(b) #返回交集 s.intersection_update(b) #将s更新为交集 s.isdisjoint(b) #有交集是False,没有交集是True s.issubset(b) #判断s是否是b的子集 s.issuperset(b) #判断s是否是b的父集 s.pop(123) #移除元素同时返回移除的元素,可以拿来赋值 a = s.symmetric_difference(b) #把在a存在b不存在的和在b存在a不存在的合在一起 s.symmetric_difference_update(b) a = s.union(b) #返回并集 a = s.update(b) #其中b为可迭代的对象,遍历添加到s集合里面