#set 集合 fronzenset (不可变集合) 无序, 不重复, 传入一个可迭代的对象
# s = set('abcdee')
# s = set(['a','b','c','d','e'])
s = {'a','b', 'c'}
# s = frozenset("abcde") #frozenset 可以作为dict的key,不可变,不能使用add或其他添加方法
# print(s)
#向set添加数据
another_set = set("cef")
s.update(another_set) #c和another_set合起来然后去重
#difference
s = {'a','b', 'c'}
another_set = set("cef")
re_set = s.difference(another_set) #返回一个新的set
#相当于 s - another_set,存在于s,但不存在于re_set的。
#set性能很高
# | & - #集合运算
re_set = s - another_set #差
re_set = s & another_set #并集 (相同的)
re_set = s | another_set #联合
print(re_set)
print (s.issubset(re_set)) #Report whether another set contains this set. """
# if "c" in re_set:
# print ("i am in set")
【python】set和frozenset
猜你喜欢
转载自blog.csdn.net/qq_38065133/article/details/82527324
今日推荐
周排行