Python中使用items()方法返回字典元素对的教程

yipeiwu_com6年前Python基础

 items()方法返回字典的(键,值)元组对的列表
语法

以下是items()方法的语法:

dict.items()

参数

  •     NA

返回值

此方法返回元组对的列表。
例子

下面的例子显示了items()方法的使用。

#!/usr/bin/python

dict = {'Name': 'Zara', 'Age': 7}

print "Value : %s" % dict.items()

当我们运行上面的程序,它会产生以下结果:

Value : [('Age', 7), ('Name', 'Zara')]

相关文章

python中count函数简单用法

python中count函数的用法 Python count()方法 描述 Python count() 方法用于统计字符串里某个字符出现的次数。可选参数为在字符串搜索的开始与结束位置。...

Python shutil模块用法实例分析

本文实例讲述了Python shutil模块用法。分享给大家供大家参考,具体如下: shutil模块 主要作用与拷贝文件用的。 1.shutil.copyfileobj(文件1,文件2)...

解析PyCharm Python运行权限问题

解析PyCharm Python运行权限问题

先通过 which python 获得 python 指令所在路径: $ which python /usr/bin/python 如上得到了其所在路径是 /usr/bin/pyt...

用Eclipse写python程序

用Eclipse写python程序

在上一篇文章里已经写过如何安装python和在eclipse中配置python插件,这篇就不多说了,开始入门。 1.先新建一个python工程,File-->New-->Ot...

详解Python 中sys.stdin.readline()的用法

之前在Python中输入都是用的input(),但是看到大家都用sys.stdin.readline(),没办法那我也得用. python3中使用sys.stdin.readline()...