其他分享
首页 > 其他分享> > 字典常用操作

字典常用操作

作者:互联网

字典常用操作## 标题
info = {
“stu1101”:“Teng WU”,
“stu1102”:“Eng Meng”,
“stu1103”:“Xiao Wei”,
“stu1104”:“He Ku”,
“stu1105”:“Chen Fei”,
}
print(info)
info[“stu1101”] = “哼哼”

{‘stu1101’: ‘哼哼’, ‘stu1102’: ‘Eng Meng’, ‘stu1103’: ‘Xiao Wei’, ‘stu1104’: ‘He Ku’, ‘stu1105’: ‘Chen Fei’}

info[“stu1102”] = “黄钰”

{‘stu1101’: ‘Teng WU’, ‘stu1102’: ‘黄钰’, ‘stu1103’: ‘Xiao Wei’, ‘stu1104’: ‘He Ku’, ‘stu1105’: ‘Chen Fei’}

del info[“stu1101”] #删除

{‘stu1102’: ‘Eng Meng’, ‘stu1103’: ‘Xiao Wei’, ‘stu1104’: ‘He Ku’, ‘stu1105’: ‘Chen Fei’}

info.pop(‘stu1101’) #删除

{‘stu1102’: ‘Eng Meng’, ‘stu1103’: ‘Xiao Wei’, ‘stu1104’: ‘He Ku’, ‘stu1105’: ‘Chen Fei’}

info.popitem() #随机删除

{‘stu1101’: ‘Teng WU’, ‘stu1102’: ‘Eng Meng’, ‘stu1103’: ‘Xiao Wei’, ‘stu1104’: ‘He Ku’}

print(info.get(‘stu1103’)) #取stu1103的值

Xiao Wei

qq_43619747 发布了2 篇原创文章 · 获赞 0 · 访问量 12 私信 关注

标签:stu1103,info,常用,stu1102,Wei,stu1101,Xiao,操作,字典
来源: https://blog.csdn.net/qq_43619747/article/details/104159478