python基础—字典的使用{}

info = {'stu1':"lili",
'stu2':'yoyo',
'stu3':'dudu'}
print(info)
print(info['stu1'])
info['stu4'] = '丽'
print(info.get('stu2'))
b = {
'stu1':'lilililili',
1:2,
2:3
}
info.update(b)#合并两个字典,有交叉就覆盖
print(info)
print(info.items())#字典转成了列表
c = dict.fromkeys([6,7,8],'tttttttt')#新建字典传入key,value,三个key的value相同
print(c)

'''
del info['stu1']
info.pop('stu1')
info.popitem()#随机删
print(info)

print('stu2' in info)#查找,true,false
'''
上一篇:面向对象


下一篇:成绩排序