#字典的特性 # 。dict是无序的 # 。key必须是唯一的,so天生去重
dixt = {'caicai':33 , 'wuwu':22}
of = {'xingming':'caicai' ,"age":33,"opne":13421731046,"qq":75738369} #如果有xingming这个key存在,就修改,如果不存在就创建 of["xingming"] = "菜菜" of["XingM"] = "菜菜" ##删除 del of["XingM"] of.pop("xingming") #随机删除 of.popitem() #查找--如果没有找到就返回None,找到就返回值 print(of.get("opne")) #查找--如果找到就返回True,没有找到就返回False print('opne' in of) print(of)
###多层嵌套 catalog = { "oumei":{"www01":["01","01"],"www02":"02","www03":"03"}, "rihan":{"www04":"04","www05":"05","www06":"06"}, "dalu":{"www07":"07","www08":"08","www09":"09"} } ###修改一个值 catalog["oumei"]["www01"][1] = "08" print(catalog)
##如果有这个字典就更新,没有就创建 b = {'dalu': {'www17': '17', 'www18': '18', 'www19': '19'}} catalog.update(b) print(catalog)
#字典中的循环 for i in catalog: print(i,catalog[i])
##会先把dict转成tuple,数据量大时莫用 for k, v in catalog.items(): print(k,v)