s = {1, 1, 1, 1, 1, 3, 5, 67, 89}
print(s,type(s))
s1 = {}
print(type(s1)) # 默认情况下是dict
s2 = set([]) # 定义一个空集合
print(s2,type(s2))
集合只支持成员操作符、for循环
s = {1,2,3}
print(1 in s)
print(1 not in s)
s = {1,2,3}
for i in s:
print(i,end='')
print()
集合是一个可变的数据类型
添加顺序和存储顺序是不一样的
s = {4,5,6,7,8,9,2}
print(s)
#添加一个元素s.add()
s.add(10)
s.add(0)
print(s)
#添加多个元素a.update()
s.update({3,6,7,8})
print(s)
s = {4,5,6,7,8,9,2}
a = s.pop()
print(s)
print(a)
# 删除指定的元素
s.remove(9)
print(s)
s1 = {2,3,1}
sorted(s1)
print(s1)
s1 = {2,3,1}
s2 = {2,3,4}
print('并集:',s1.union(s2))
print('并集:',s1 | s2)
s1 = {2,3,1}
s2 = {2,3,4}
print('交集:',s1.intersection(s2))
print('交集:',s1 & s2)
s1和s2的差集 :s1中有哪些s2中没有的元素
s1 = {2,3,1}
s2 = {2,3,4}
print('差集:',s1.difference(s2))
print('差集:',s1 -s2)
对等差分:并集- 交集
s1 = {2,3,1}
s2 = {2,3,4}
print('对等差分:',s1.symmetric_difference(s2))
print('对等差分:',s1 ^ s2)
s1.issubset(s2):s1是否是s2的子集
s1.isdisjoint(s2):两个集合是不是不相交
s1 = {'westos','redhat','python'}
s2 = {'redhat','westos','linux'}
# s1是否是s2的子集
print(s1.issubset(s2))
# 两个集合是不是不相交
print(s1.isdisjoint(s2))
列表快速去重
li = [1,2,3,4,5,6,6,6,7,8,9,9,9]
print(list(set(li)))