集合

# 把不同的元素组合在一起
# 创建方法:
# 集合名=set(不同的元素)
# a=set(["a","bf","c",1,2,3])
# b=set(["f","rg","okf",9,7,6])
# 判断某个元素在不在集合中,用in 或not in、
# print("bfde" in a)
# print("bf" in a)
# print("bf" not in a)
# 集合两个作用:
# 去重,关系测试
# 集合的更新:
# 1,add把元素打包,当一个元素添加
# a.add(8)
# print(a)
# 2,update把元素分开变成一个序列来添加,且消除重复
# a.update("jdhjgh")
# print(a)
# 3,remove删除某个元素
# a.remove("bf")
# print(a)
# 4,pop随机删除
# 5,clear清空集合
# 6,del删除整个集合

# a=set(["a","bf","c",1,9,7,3])
# b=set(["f","rg","okf",9,7,6])
# ==相等
# 交集:a.intersection(b)或用& 求ab的交集
# print(a&b)
# 并集:a.union(b)或用| 求ab的并集
# print(a|b)
# 差集:a.difference(b) 或用- 求a里面有但是b里面没有
# print(a-b)
# 反向交集:a.symmertric_difference(b)或用^ 求a中有b中没有的
# 父集,超集
# a=set(["a","bf"])
# b=set(["f","rg","a","bf"])
# a.issuperset(b) >父集
# print(a<b)
# a.issubset(b) < 子集
# print(a>b)
原文地址:https://www.cnblogs.com/laoli1020/p/8456393.html