python字典中items()函數(shù)用法實例
items() 函數(shù)以列表返回可遍歷的(鍵, 值) 元組。
將字典中的鍵值對以元組存儲,并將眾多元組存在列表中。
如:
favorite_places = {'XiaoMing': 'TJL','XiaoQiang':'Amercia','Dongsheng':'Japan'}
print("數(shù)值:%s" % favorite_places.items())
for key,value in favorite_places.items():
print(key,value)數(shù)值:dict_items([('XiaoQiang', 'Amercia'), ('Dongsheng', 'Japan'), ('XiaoMing', 'TJL')])
XiaoQiang Amercia
Dongsheng Japan
XiaoMing TJL
具體可以參考以下的例子,十分明顯

python3.5中的解釋:
def items(self): # real signature unknown; restored from __doc__
""" D.items() -> a set-like object providing a view on D's items """
pass附:實例
dict = {'老大':'15歲',
'老二':'14歲',
'老三':'2歲',
'老四':'在墻上'
}
print(dict.items())
for key,values in dict.items():
print(key + '已經(jīng)' + values + '了')
以上實例輸出結(jié)果為:
dict_items([('老大', '15歲'), ('老二', '14歲'), ('老三', '2歲'), ('老四', '在墻上')])
老大已經(jīng)15歲了
老二已經(jīng)14歲了
老三已經(jīng)2歲了
老四已經(jīng)在墻上了了
總結(jié)
到此這篇關(guān)于python字典中items()函數(shù)用法的文章就介紹到這了,更多相關(guān)python字典items()函數(shù)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
python解決報錯ImportError: Bad git executable.問題
這篇文章主要介紹了python解決報錯ImportError: Bad git executable.問題。具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-06-06
python?lazypredict構(gòu)建大量基本模型簡化機(jī)器學(xué)習(xí)
這篇文章主要介紹了python?lazypredict構(gòu)建大量基本模型簡化機(jī)器學(xué)習(xí),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2024-01-01
基于Python實現(xiàn)MUI側(cè)滑菜單a標(biāo)簽跳轉(zhuǎn)
這篇文章主要介紹了基于Python實現(xiàn)MUI側(cè)滑菜單a標(biāo)簽跳轉(zhuǎn),mui最接近原生APP體驗的高性能前端框架,MUI側(cè)滑常見的場景有下拉刷新,側(cè)滑抽屜,側(cè)滑刪除,側(cè)滑返回以及側(cè)滑菜單等等,下面來看看文章內(nèi)容詳細(xì)的介紹,需要的朋友可以參考一下2021-11-11

