#! /usr/bin/env python #! -*- cording:utf-8 -*- li=[11,22,33] new_dict=dict(enumerate(li,10))#加一个序号,是10 print(new_dict) dic={"k1":123,"k2":456,"k4":111} #dic.get() #k1k2默认值123 n=dic.fromkeys([‘k1‘,‘k2‘,‘k3‘],‘alex‘) #更新values值 print(n) n2={‘k1‘:[],‘k2‘:[],‘k3‘:[]} print(n2) n2[‘k1‘].append(‘x‘) print(n2) #在每个元素里都加了x,用fromkeys去创建k1k2k3时共同创建了一个列表。一旦更新k1就会都更新 n3=dict.fromkeys([‘k1‘,‘k2‘,‘k3‘],[]) print(n3) n3[‘k1‘].append(‘x‘) print(n3)
时间: 2024-12-20 18:15:28