python語法中, items用於字典, 作用是以列表返回可遍歷的(key, value)的元組數組
1. 語法
1 dict.items()
2. 實例
(1) 代碼
1 #!/usr/bin/env python 2 # coding=utf-8 3 4 dict_a = { 5 (1, 2, 3) : "helloworld", 6 "baidu" : "www.baidu.com", 7 "we are young" : "YES!" 8 } 9 10 for key, value in dict_a.items(): 11 print str(key) + "=" + str(value)
(2) 結果
baidu=www.baidu.com
we are young=YES!
(1, 2, 3)=helloworld