1、遍历key值
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
>>> 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、使用字典自带函数values()、items()。
(1)使用values()遍历
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
>>> for value in a.values(): print(value) 1 2 3
(2)使用items()遍历
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
>>> for kv in a.items(): print(kv) ('a', '1') ('b', '2') ('c', '3')
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
>>> 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