Python 字典(Dictionary) items()方法


描述

Python 字典(Dictionary) items() 函數以列表返回可遍曆的(鍵, 值) 元組數組。

語法

items()方法語法:

dict.items()

參數

  • NA。

返回值

返回可遍曆的(鍵, 值) 元組數組。

實例

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

實例(Python 2.0+)

#!/usr/bin/python # coding=utf-8 dict = {'Google': 'www.google.com', 'zaixian': 'www.xuhuhu.com', 'taobao': 'www.taobao.com'} print "字典值 : %s" % dict.items() # 遍曆字典列表 for key,values in dict.items(): print key,values

以上實例輸出結果為:

字典值 : [('Google', 'www.google.com'), ('taobao', 'www.taobao.com'), ('zaixian', 'www.xuhuhu.com')]
Google www.google.com
taobao www.taobao.com
zaixian www.xuhuhu.com