dic1 = {'李宁':'一切皆有可能','耐克':'Just Do it','阿迪达斯':'Impossible is nothing'}
dic1
{'李宁': '一切皆有可能', '耐克': 'Just Do it', '阿迪达斯': 'Impossible is nothing'}
for each in dic1:
print("%s --> %s"%(each,dic1[each]))
李宁 --> 一切皆有可能
耐克 --> Just Do it
阿迪达斯 --> Impossible is nothing
dic1 = {}
dic1.fromkeys((1,2,3))
{1: None, 2: None, 3: None}
dic2={}
dic2.fromkeys((1,2,3),"Number")
{1: 'Number', 2: 'Number', 3: 'Number'}
dic3={}
dic3.fromkeys((1,2,3),("One","Two","Three"))
{1: ('One', 'Two', 'Three'), 2: ('One', 'Two', 'Three'), 3: ('One', 'Two', 'Three')}
使用keys(),values(),items()来为字典赋值
使用get()方法去访问字典项
使用clear()来清除字典 不要使用变量名赋值为一个空字典的方法
copy()浅拷贝
pop()给定键弹出对于的值
popitem()是弹出一个项
saedefault()与get()类似 但在找不到相应的键时会自动添加
update()更新字典