代码块:
s = {6,7,8,9}
#增加
s.add(1)
print(s)
s.update({5,2,3})
print(s)
代码块:
s = {6,7,8,9}
#删除
s.pop()
print(s)
s.remove(2)
print(s)
代码块:
s1 = {1,2,3}
s2 = {2,3,4}
#交集
print('交集: ',s1.intersection(s2))
print('交集: ',s1 & s2)
代码块:
s1 = {1,2,3}
s2 = {2,3,4}
#并集
print('并集: ',s1.union(s2))
print('并集: ',s1 | s2)
代码块:
s1 = {1,2,3}
s2 = {2,3,4}
#差集
print('差集: ',s1.difference(s2)) #s1 - (s1&s2)
print('差集: ',s2.difference(s1)) #s2 - (s1&s2)
代码块:
s1 = {1,2,3}
s2 = {2,3,4}
#对等差分:并集-交集
print('对等差分:',s2.symmetric_difference(s1))
print('对等差分:',s1^s2)
代码块:
s3 = {4,5,6}
s4 = {1,2,3}
print(s3.issuperset(s4))
print(s3.issubset(s4))
print(s3.isdisjoint(s4))