标签:oar tboot shc lse directory tween 3.3 eth local
集合
s1 = set()
s2 = set((1,2,3))
s3 = {1,2,3}
print(s1,type(s1))
print(s2,type(s2))
print(s3,type(s3))
# 增加
s1 = {1,2,3}
# add() 添加单个元素
s1.add(4)
print(s1)
# update() 可迭代类型
s1.update([5,6,7])
print(s1)
# 删除
s1 = {1,2,3,4}
# 随机删除
res = s1.pop()
print(res)
# 指定元素删除
res = s1.remove(4)
print(s1)
# 清空
s1.clear()
print(s1)
s1 = {1,2,3,4,5}
s2 = {3,4,5,6,7,8,}
# 交集
res = s1&s2
print(res)
# 并集
res = s1|s2
print(res)
# 差集
print(s1-s2)
print(s2-s1)
# 交差补集
print(s1^s2)
s3 = {1,2,3,}
s4 = {1,2,3,4,5}
# s4是否是s3的超集
print(s4>s3)
# s3是否是s4的子集
print(s3<s4)
# 集合本身是可变的数据类型,可利用frozenser来变成不可变数据类型
s1 = {1,2,3,4}
s2 = frozenset(s1)
print(s1,type(s1))
print(s2,type(s2))
# for i in s2:
# print(i)
for j in s2:
print(j)
# 不可修改
s2.add(1)
s2.clear()
标签:oar tboot shc lse directory tween 3.3 eth local
原文地址:https://www.cnblogs.com/xjmlove/p/10127796.html