Python字典items()方法

Python字典items()方法用于返回字典dict(key,value)元组对的列表

语法

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

dict.items()

参数

  • NA

返回值

  • 此方法返回一个元组对列表。

示例

以下示例显示items()方法的用法 -

#!/usr/bin/python

dict = {'Name': 'Maxsu', 'Age': 27}
print ("Value : %s" %  dict.items())

当运行上面的程序,它产生以下结果 -

Value : [('Age', 27), ('Name', 'Maxsu')]

上一篇: Python字典 下一篇: Python日期和时间