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

在蓬萊等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供網(wǎng)站設(shè)計制作、網(wǎng)站建設(shè) 網(wǎng)站設(shè)計制作定制網(wǎng)站建設(shè),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站制作,成都全網(wǎng)營銷推廣,成都外貿(mào)網(wǎng)站建設(shè)公司,蓬萊網(wǎng)站建設(shè)費用合理。
python學習網(wǎng),大量的免費python視頻教程,歡迎在線學習!
①
>>> d={'list':[1, 2, 3],1:123,'111':'python3','tuple':(4, 5, 6)}
>>> for key in d:
print(str(key)+':'+str(d[key]))
list:[1, 2, 3]
1:123
111:python3
tuple:(4, 5, 6)相關(guān)推薦:《Python教程》
②
>>> d={'list':[1, 2, 3],1:123,'111':'python3','tuple':(4, 5, 6)}
>>> for key in d.keys():
print(key)
1
list
111
tuple2. 遍歷字典的值value
>>> d={'list':[1, 2, 3],1:123,'111':'python3','tuple':(4, 5, 6)}
>>> for value in d.values():
print (value)
[1, 2, 3]
123
python3
(4, 5, 6)3. 遍歷字典的項
>>> d={'list':[1, 2, 3],1:123,'111':'python3','tuple':(4, 5, 6)}
>>> for item in d.items():
print(item)
('list', [1, 2, 3])
(1, 123)
('111', 'python3')
('tuple', (4, 5, 6))4. 遍歷字典的key-value
①
>>> d={'list':[1, 2, 3],1:123,'111':'python3','tuple':(4, 5, 6)}
>>> for key,value in d.items():
print(key,value)
list [1, 2, 3]
1 123
111 python3
tuple (4, 5, 6)②
>>> d={'list':[1, 2, 3],1:123,'111':'python3','tuple':(4, 5, 6)}
>>> for (key,value) in d.items():
print(key,value)
list [1, 2, 3]
1 123
111 python3
tuple (4, 5, 6) 網(wǎng)頁標題:創(chuàng)新互聯(lián)Python教程:python中如何遍歷字典
分享路徑:http://m.fisionsoft.com.cn/article/dhoogee.html


咨詢
建站咨詢
