集合是Python提供的内置数据结构
与列表、字典一样都属于可变类型的序列
集合是没有value的字典
只能存储不同的值
s={'hello','world',1314}
s=set(range(6))
print(s)
print(set([3,4,53,56]))
print(set((3,4,43,435)))
print(set('Python')
print(set({124,3,4,4,5}))
print(set())
in或者not in
s = {1, 2, 3, 4, 5, 6, 99, 7, 100}
print(s) # {1, 2, 3, 4, 5, 6, 99, 7, 100}
print(1 in s) # True
print(10 in s) # False
print(20 not in s) # True
s = {1, 2, 3, 4, 5, 6, 7}
s.add(8)
print(s) # {1, 2, 3, 4, 5, 6, 7, 8}
s = {1, 2, 3, 4, 5, 6, 7}
s.update({8,9})
print(s) # {1, 2, 3, 4, 5, 6, 7, 8, 9}
s1 = {1, 2, 3}
s2 = {1, 2, 3, 10}
print(s1.issubset(s2)) # true
s1 = {1, 2, 3}
s2 = {1, 2, 3, 10}
print(s2.issuperset(s1)) # true
s1 = {1, 2, 3, 11}
s2 = {1, 2, 3, 10}
s3 = {4, 5, 6}
print(s2.isdisjoint(s1)) # False 意思是有交集
print(s2.isdisjoint(s2)) # True 意思是有交集
s1 = {1, 2, 3, 11}
s2 = {1, 2, 3, 10}
print(s1.intersection(s2)) # {1, 2, 3}
s1 = {1, 2, 3, 11}
s2 = {1, 2, 3, 10}
print(s1.union(s2)) # {1, 2, 3, 10, 11}
s1 = {1, 2, 3, 11}
s2 = {1, 2, 3, 10}
print(s1-s2) # { 11 }
print(s1.difference(s2)) # { 11 }
s1 = {1, 2, 3, 11}
s2 = {1, 2, 3, 10}
s1 = {1, 2, 3, 11}
s2 = {1, 2, 3, 10}
print((s2 - s1) | (s1 - s2)) # {10, 11}
print(s2.symmetric_difference(s1)) # {10, 11}
{ i*i for i in range(1,10) }
s = {i*i for i in range(1,10)}
print(s) # {64, 1, 4, 36, 9, 16, 49, 81, 25}