首页 > 编程 > Python > 正文

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

2020-02-23 01:21:16
字体:
来源:转载
供稿:网友

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

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

dict.items()

参数

    NA

返回值

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

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

#!/usr/bin/pythondict = {'Name': 'Zara', 'Age': 7}print "Value : %s" % dict.items()

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

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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表