标签:ict python update items pytho none get pop TE
一、get方法
dict = {‘k1‘:1,‘k2‘:2}
dict.get(‘k1‘)
1
dict.get(‘k2‘)
2
dict.get(‘k3‘)
None
dict.get(‘k3‘,‘wohaoshuai‘)
wohaoshuai
(如果k3不存在那么就设置为wohaoshuai)
二、items
dict.items()
dict_items([(‘a‘, 1), (‘b‘, 2)])
三、pop
dict.pop(‘k1‘)
dict
{‘k2‘:2}
四、update
d2 = {‘k3‘:3}
dict.update(d2)
dict
{‘k1‘:1,‘k2‘:2,‘k3‘:3}
Python dict get items pop update
标签:ict python update items pytho none get pop TE
原文地址:https://www.cnblogs.com/Presley-lpc/p/9160328.html