python之字典dict的for循环
以下方法等同,都可以获取key和value
1.#获取KEY和value
dir_test={ 'n':"psu",'v':"电压",'c':"电流"}
for key,value in dir_test.items():
print(key,value)
2#获取KEY和value
for i,j in dir_test.items():
#print("key:%s"%i,"value:%s"%dir_test[i])
print("key:%s"%i,"value:%s"%j)
#获取value
for value in dir_test.values():
print(value)
#获取key
for key in dir_test.keys():
print(key)