整理相关知识点
#conding=utf-8
#空的字典
dictionary={}
dictionary2 = dict()
#创建字典
dictionary={'key1':'值1','key2':'值2','key3':'值3'}
list1=['zhu','zhuzhu','zhuzhuzhu']
list2=['朱','朱朱','朱朱朱']
dictionary2=dict(zip(list1,list2))
dictionary3=dict(no1='号码1',no2='号码2',no3='号码3')
dictionary4=dict.fromkeys(list2)
print(dictionary)
print(dictionary2)
print(dictionary3)
print(dictionary4)
#获取字典值
print(dictionary['key2'])
print(dictionary2.get('zhu'))
print(dictionary2.get('zhu2'))
print(dictionary2.get('zhu3','对应KEY值元素不存在'))
#添加元素
dictionary['key4']='添加元素值'
#修改元素
dictionary['key3']='修改元素值'
print(dictionary)
#删除元素
del dictionary4['朱']
print(dictionary4)
dictionary3.clear()
print(dictionary3)
del dictionary4
for item in dictionary2:
print(item,end=' ')
|