好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

什么是pythonitems函数?怎么使用它?

这篇文章我们来学习一下关于python字典之中的 python items函数 的相关知识,i tems函数 是什么意思,这个函数有什么作用都将会在接下来的文章之中得到解答。

描述

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

语法

items()方法语法:

dict.items() 

参数

NA。

返回值

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

实例

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

# !/usr/bin/python
# coding=utf-8

dict = {'Google': 'HdhCmsTestgoogle测试数据', 'Runoob': 'HdhCmsTestrunoob测试数据', 'taobao': 'HdhCmsTesttaobao测试数据'}

print "字典值 : %s" % dict.items()

# 遍历字典列表
for key, values in dict.items():
    print key, values 

以上实例 输出 结果为:

字典值 : [('Google', 'HdhCmsTestgoogle测试数据'), ('taobao', 'HdhCmsTesttaobao测试数据'), ('Runoob', 'HdhCmsTestrunoob测试数据')]
Google HdhCmsTestgoogle测试数据
taobao HdhCmsTesttaobao测试数据
Runoob HdhCmsTestrunoob测试数据 

以上就是这篇文章所讲的全部内容,python中字典内置的items函数。希望所说的内容以及所举的例子能对你有所帮助。

更多相关知识,请访问Gxl网Python教程栏目。

以上就是什么是python items函数?怎么使用它?的详细内容,更多请关注Gxl网其它相关文章!

查看更多关于什么是pythonitems函数?怎么使用它?的详细内容...

  阅读:42次