1、遍历key值,value值(下面写法完全等价): a = {'a': '1', 'b': '2', 'c': '3'} 方式一: for key in a: print(key+':'+a[key]) 方式二: for key in a.keys(): print(key+':'+a[key]) 方式三: for key,value in a.items(): print(key+':'+value) 方式四: for (key,val...
print(kv) ('a', '1') ('b', '2') ('c', '3') 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 根据字典键值对遍历 >>> 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 1. 2....
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 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 在使用上,for key in a和 for key in a.keys():完全等价。 2.遍历value值 >>> for value in a.values(...
>>> for key in a.keys(): print(key+':'+a[key]) a:1 b:2 1. 2. 3. 4. 5. 2)遍历value值 >>> for value in a.values(): print(value) 1 2 3 1. 2. 3. 4. 5. 6. >>> for kv in a.items(): print(kv) ('a', '1') ...