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日期和時間