dic={1:'alex','age':35,'hobby':{'girl_name':'铁锤','age':45},'is_handsome':True} dic={'age':'alex','age':35,'hobby':{'girl_name':'铁锤','age':45},'is_handsome':True} print(dic) 字典两大特点:无序,键唯一 字典的创建 a=list() print(a) dic={'name':'alex'} dic1={} dic2=dict((('name','alex'),)) print(dic2) dic1={'name':'alex'} dic1['age']=18 print(dic1) 键存在,不改动,返回字典中相应的键对应的值 ret=dic1.setdefault('age',34) print(ret) #键不存在,在字典中中增加新的键值对,并返回相应的值 ret2=dic1.setdefault('hobby','girl') print(dic1) print(ret2) dic3=dict([['name','alex'],]) print(dic3) 查 通过键去查找 dic3={'age': 18, 'name': 'alex', 'hobby': 'girl'} print(dic3['name']) print(list(dic3.keys())) print(list(dic3.values())) print(list(dic3.items()))