新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python如何遍歷dict
python遍歷字典有以下幾種方式

我們先創(chuàng)建一個(gè)字典 D={‘a(chǎn)’:1,‘b’:2,’b‘:3,’d‘:4}
1. 遍歷key值
for key in a: pritn(key+':'+a[key]) for key in a.keys(): print(key+':'+a[key])
2.遍歷value值
for value in a.values(): print(value)
3.遍歷字典項(xiàng)
for kv in a.items(): print(kv) (‘a(chǎn)’,'1')(...)
4.遍歷字典鍵值
for key,value in a.items(): print(key+':'+value) for (key,value) in a.items(): print(key+':'+value)
新聞名稱:創(chuàng)新互聯(lián)Python教程:python如何遍歷dict
文章轉(zhuǎn)載:http://fisionsoft.com.cn/article/cciihgp.html


咨詢
建站咨詢
