'''字典'''
编程语言
2019-03-12 21:42:07
阅读次数: 0
‘’‘字典’’’
键值结构,dict_new={‘name’:‘xu’,‘age’:18,‘tel’:123}
dict_new={‘name’:‘xiaoxu’,‘age’:18,‘tel’:123}
print(dict_new.keys())
print(dict_new.values())
print(dict_new[‘name’])
字典查询与修改
print(dict_new[‘age’])
get
ret1=dict_new.get(‘name1’)# get获取指定键值,有则返回默认值,若无则返回none,不存在不报错
print(ret1)
dict_new[‘name’]=‘爸爸’#键名存在,则对存在的键名对应的值进行修改
dict_new[‘name1’]=‘儿子’#键名不存在,则在原来的字典中增加该键值结构
print(dict_new)
#del与clear
list_new=[1,2,2,]
#删除指定元素
del list_new[0]
del dict_new[‘tel’]
#删除整个列表字典
del dict_new
del list_new
# print(list_new)
dict_new.clear()
print(dict_new)
转载自blog.csdn.net/qq_44090577/article/details/88425704