python中items()函数
程序员文章站
2022-06-17 14:38:41
items() 函数以列表返回可遍历的(键, 值) 元组。将字典中的键值对以元组存储,并将众多元组存在列表中。如:favorite_places = {'XiaoMing': 'TJL','XiaoQiang':'Amercia','Dongsheng':'Japan'}print("数值:%s" % favorite_places.items())for key,value in favorite_places.items(): print(key,value)数值:dic....
items() 函数以列表返回可遍历的(键, 值) 元组。
将字典中的键值对以元组存储,并将众多元组存在列表中。
如:
favorite_places = {'XiaoMing': 'TJL','XiaoQiang':'Amercia','Dongsheng':'Japan'}
print("数值:%s" % favorite_places.items())
for key,value in favorite_places.items():
print(key,value)
数值: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
本文地址:https://blog.csdn.net/hellfu/article/details/110875605