python items()方法如何使用-Python教程

资源魔 31 0

python items()办法若何应用?

Python 字典(Dictionary) items()办法

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

保举:《Python教程》

语法

items()办法语法:

dict.items()

参数

NA。

前往值

前往可遍历的(键, 值) 元组数组。

如下实例展现了 items()函数的应用办法:

实例(Python 2.0+)

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

以上实例输入后果为:

字典值 : [('Google', 'www.谷歌.com'), ('taobao', 'www.taobao.com'), ('Runoob', 'www.php.cn')]
Google www.谷歌.com
taobao www.taobao.com  
php www.php.cn

以上就是python items()办法若何应用的具体内容,更多请存眷资源魔其它相干文章!

标签: Python python教程 python编程 python使用问题

抱歉,评论功能暂时关闭!