本文摘自php中文网,作者藏色散人,侵删。

python items()方法如何使用?
Python 字典(Dictionary) items()方法
Python 字典(Dictionary) items() 函数以列表返回可遍历的(键, 值) 元组数组。
推荐:《Python教程》
语法
items()方法语法:
参数
NA。
返回值
返回可遍历的(键, 值) 元组数组。
以下实例展示了 items()函数的使用方法:
实例(Python 2.0+)
1 2 3 4 5 6 7 8 9 10 | #!/usr/bin/python
# coding=utf-8
dict = { 'Google' : 'www.google.com' , 'Runoob' : 'www.php.cn' , 'taobao' : 'www.taobao.com' }
print "字典值 : %s" % dict.items()
# 遍历字典列表
for key,values in dict.items():
print key,values
|
以上实例输出结果为:
1 2 3 4 | 字典值 : [( 'Google' , 'www.google.com' ), ( 'taobao' , 'www.taobao.com' ), ( 'Runoob' , 'www.php.cn' )]
Google www.google.com
taobao www.taobao.com
php www.php.cn
|
以上就是python items()方法如何使用的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
初学Python需要有什么基础么
Python后端开发学习什么
Python实现读取字符串按列分配后按行输出
Python详细安装方法
Python怎么合并两个字典
Python里的self用法
Python元组的知识详解
r vs. Python数据分析详解
Python编程如何求2000到2500闰年?
Python怎么安装numpy模块?
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python items()方法如何使用