Python 字典(Dictionary) items()方法

Python 教程 · 2019-02-03 07:58:18

描述

Python 字典(Dictionary) items() 函数以列表返回可遍历的(键, 值) 元组数组。

语法

items()方法语法:

dict.items()

参数

  • NA。

返回值

返回可遍历的(键, 值) 元组数组。

实例

以下实例展示了 items()函数的使用方法:

实例(Python 2.0+)

#!/usr/bin/python # coding=utf-8 dict = {'Google': 'www.google.com', 'Codercto': 'www.codercto.com', 'taobao': 'www.taobao.com'} print "字典值 : %s" % dict.items() # 遍历字典列表 for key,values in dict.items(): print key,values

以上实例输出结果为:

字典值 : [('Google', 'www.google.com'), ('taobao', 'www.taobao.com'), ('Codercto', 'www.codercto.com')]
Google www.google.com
taobao www.taobao.com
Codercto www.codercto.com

点击查看所有 Python 教程 文章: https://www.codercto.com/courses/l/8.html

查看所有标签

大视觉创意宝典

大视觉创意宝典

2008-8 / 28.00元

《大视觉创意宝典:网页设计》主要内容:将优秀的网页分为设计、卡通、教育、金融、通讯、企业、房地产、娱乐等十四个章节,并详尽解析其页面布局、配色参考、设计特色及细节元素。丛书编写以设计基础的角度出发,具备速查、参照、案头工具书等功能。一起来看看 《大视觉创意宝典》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

在线进制转换器
在线进制转换器

各进制数互转换器

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码