教育行業(yè)A股IPO第一股(股票代碼 003032)

全國(guó)咨詢/投訴熱線:400-618-4000

遍歷python字典:如何遍歷python字典里每一個(gè)鍵

更新時(shí)間:2021年12月21日16時(shí)02分 來(lái)源:傳智教育 瀏覽次數(shù):

好口碑IT培訓(xùn)

Python字典的for循環(huán)遍歷

1.  遍歷key的值

scores_dict = {'語(yǔ)文': 105, '數(shù)學(xué)': 140, '英語(yǔ)': 120}
for key in scores_dict:
print(key)
python字典遍歷Key值

2.   遍歷value的值

scores_dict = {'語(yǔ)文': 105, '數(shù)學(xué)': 140, '英語(yǔ)': 120}
for value in scores_dict.values():
    print(value)
python字典遍歷vlaue值

3.  遍歷字典鍵值對(duì)

scores_dict = {'語(yǔ)文': 105, '數(shù)學(xué)': 140, '英語(yǔ)': 120}
for key in scores_dict:
print(key + ":" + str(scores_dict[key]))    # 返回字符串
遍歷字典
scores_dict = {'語(yǔ)文': 105, '數(shù)學(xué)': 140, '英語(yǔ)': 120}
for i in scores_dict.items():
print(i)    # 返回元組

遍歷字典返回元組


scores_dict = {'語(yǔ)文': 105, '數(shù)學(xué)': 140, '英語(yǔ)': 120}
for key, value in scores_dict.items():
    print(key + ':' + str(value))
遍歷字典鍵值對(duì)

2. Python字典視頻教程

加QQ:435946716獲取上面視頻的全套資料【視頻+筆記+源碼】



猜你喜歡:

python字典如何使用?有哪些應(yīng)用場(chǎng)景

Python中字典的常見(jiàn)操作

Python中的字典是什么?怎么通過(guò)字典查詢信息?

Python下載和安裝圖文教程[超詳細(xì)]【附贈(zèng)19天全套Python視頻教程】

傳智教育Python+大數(shù)據(jù)開(kāi)發(fā)課程

0 分享到:
和我們?cè)诰€交談!