日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無(wú)先后,達(dá)者為師

網(wǎng)站首頁(yè) 編程語(yǔ)言 正文

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

作者:工具人01 ? 更新時(shí)間: 2022-12-25 編程語(yǔ)言

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é)

原文鏈接:https://blog.csdn.net/hellfu/article/details/110875605

欄目分類
最近更新