在python中对字典进行遍历的方法有以下几种
1.通过key值遍历
>>> a
{'a': '1', 'b': '2', 'c': '3'}
>>> for key in a:
print(key+':'+a[key])
a:1
b:2
c:3
>>> for key in a.keys():
print(key+':'+a[key])
a:1
b:2
c:3
2.通过字典项遍历
>>> for kv in a.items():
print(kv)
('a', '1')
('b', '2')
('c', '3')
3.通过字典健值遍历
>>> for key,value in a.items():
print(key+':'+value)
a:1
b:2
c:3
>>> for (key,value) in a.items():
print(key+':'+value)
a:1
b:2
c:3
4.通过value值遍历
>>> for value in a.values():
print(value)
1
2
3