欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python字典中items()函數(shù)用法實(shí)例

 更新時(shí)間:2022年11月28日 11:12:02   作者:工具人01  
Python字典items()函數(shù)作用以列表返回可遍歷的(鍵, 值)元組數(shù)組,下面這篇文章主要給大家介紹了關(guān)于python字典中items()函數(shù)用法的相關(guān)資料,需要的朋友可以參考下

items() 函數(shù)以列表返回可遍歷的(鍵, 值) 元組。

將字典中的鍵值對(duì)以元組存儲(chǔ),并將眾多元組存在列表中。

如:

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

附:實(shí)例

dict = {'老大':'15歲',
        '老二':'14歲',
        '老三':'2歲',
        '老四':'在墻上'
        }
print(dict.items())
for key,values in dict.items():
    print(key + '已經(jīng)' + values + '了')

以上實(shí)例輸出結(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)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論