#############字典#####################索引取值# dic={'name':'egon','zhang':123}# print(dic['zhang'])#修改值vlaue# dic={'zhang':'123','egon':456}# print(dic)# dic['zhang']='789'# print(dic)#小写转换大写# dic={'name':'egon'}# dic['name']=dic['name'].upper()# print(dic)#长度# dic={'name':'egon','age':18}# print(len(dic))#删除# dic={'name':'egon','age':18}# del dic['name']# print(dic)#删除一个元素 取到返回值 没有值 就会返回None# res=dic.pop('name')# print(res)#循环取值key# dic={'name':'egon','age':18}# print(list(dic.keys())[1])#循环取多个key# for x in dic.keys():# print (x)#循环取值values# dic={'name':'egon','age':18}# print(list(dic.values())[1]) #取vlaue值# print(dic.values()) #字典转化为列表#取多个值# for value in dic.values():# print(value)#字典转化元组# print(dic.items()) #字典转化为元组# for k,v in dic.items(): #k,v=('name','egon')# print(k,v)# for i in dic.items():# print(i[0])#根据key取value 判断这个值在不在key里面 不在返回none# dic={'name':'egon','age':18}# print(dic.get('name'))#随机产生一个元祖键值对# print(dic.popitem())#更新元素# dic.update({'x':1,'age':19}) #有就不添加 没有就添加# print(dic)#造字典# print({}.fromkeys(['name','age','sex'],None))# list1=['name','age','sex']# dic={}# for x in list1:# dic[x]=None# print(dic)# setdefault 用法# dic={'name':'egon','age':18}# 1.字典有key,则不修改,返回原key对于的原值# res=dic.setdefault('name','EGON')# print('返回值',res)#2.没有对应的key,则添加,返回添加的key对应的value# dic={'age':18}# res=dic.setdefault('name','EGON')# print('返回值',res)# print(dic)