python中items()函数
程序员文章站
2022-02-12 07:33:58
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
推荐阅读
-
PHP中fopen,file_get_contents,curl函数的区别,curlgetcontents
-
PHP中遇到BOM、feff编码导致json_decode函数无法解析问题
-
使用python提取html文件中的特定数据的实现代码
-
JavaScript中全局变量、函数内变量以及常量表达式的效率测试_javascript技巧
-
详解Python的Django框架中manage命令的使用与扩展
-
网络传输协议中的和校验函数
-
php中利用函数json_decode将json转化为数组,返回为null
-
详解Python中dict与set的使用
-
python中条件、循环等介绍说明
-
PHP中SimpleXML函数用法分析,phpsimplexml_PHP教程