字典

# dic={"易大师":"剑圣","剑豪":"托儿索","草丛伦":"大保健"}
# ret = dic.pop("易大师")#通过key删除 返回删除的vale
# print(ret)
# del dic['剑豪']
# print(dic)
# dic.clear()
# print(dic)
# ret=dic.popitem()#随机删除 返回值 一个元组 (key,value)
# print(ret)
# print(dic)
#改
# dic={"易大师":"剑圣","剑豪":"托儿索","草丛伦":"大保健"}
# dic['剑豪']='哈赛' #强制修改
# print(dic)
# dic1={'火女':'安妮','火男':'布兰德','剑豪':'哈撒'}
# dic.update(dic1) #后者被前者改变 或更新
# print(dic)
#查
# dic={"易大师":"剑圣","剑豪":"托儿索","草丛伦":"大保健"}
# for i in dic :
# print(i) # for 循环默认是获取字典中所有的键 key
# print(dic['易大师']) #有的话返回value 没有的话会报错
# print(dic.get('易大师','你傻啊!')) #有的话返回value 没有的话返回None 可以指定返回内容
# dic={"易大师":"剑圣","剑豪":"托儿索","草丛伦":"大保健"}
# print(dic.keys())
# print(dic.values())
# print(dic.items())
# dic = {'易大师':'剑圣','剑豪':'托儿所','草丛伦':'大宝剑'}
# for a,b in dic.items():
# print(a)
# print(b)
posted @ 2018-08-01 16:28  刘文文先生  阅读(189)  评论(0编辑  收藏  举报