在这里插入代码片
#集合
#intersection 交集
#difference 差集
#union 并集
#issubset 检查一个集合是否为拧一个子集
#issuperset 检查一个集合是否为d另一个的超集
a = {1,2,1,3,4,5}
b = {4,5,6,7,8}
e = a.intersection(b)
print('交集:{}'.format(e))
d = a.difference(b)
print('差集:{}'.format(d))
f = a.issubset(b)
print(f)
print('*'*20)
#集合的数学操作
g = a - b
print(g)
#f = a + b #不支持+
print('*'*20)
#frozen set 冰冻集合 不能修改
x = frozenset()
#dict 字典 以键 值对存在
#创建字典
p = {'one':1,'two':2}
#创建空字典
j = dict()
h = dict({'one':1,'two':2})
k = dict(one=1,two=2)
#以元祖的形式创建
l = dict([('one',1),('two',2)])
print(p)
print(p['one'])
p['one'] = 0
print(p['one'])
print('*'*20)
#删除字典中
del p['one']
print(p)
#成员检查 in not in
a = {'o':1,'b':2,'c':3}
print(a.keys())
print(a.values())
print('*'*20)
#字典生成
a = {'o':1,'b':2,'c':3}
dd = {k:v for k,v in a.items() if v % 2 ==0}
#字典相关函数 len max min dict
# str(字典) 返回字典的字符串格式
a = {'o':1,'b':2,'c':3}
print(str(a))
# clear 清空字典
#items 发回字典的键值对组成的元祖格式
a = {'o':1,'b':2,'c':3}
i=a.items()
print(type(i))
print(i)
print('*'*20)
#get 根据键返回相应的值
print(a.get('o'))
#可设置默认值
print(a.get('e',100))
print('*'*20)
#foemkeys 使用指定的序列作为建,使用一个值作为字典的所有的键的值
l = ['p','w','f']
d = dict.fromkeys(l,'sssss')
print(d)