Python_items()方法【详解】——Python系列学习笔记
生活随笔
收集整理的這篇文章主要介紹了
Python_items()方法【详解】——Python系列学习笔记
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
描述
Python 字典 items() 方法以列表返回可遍歷的(鍵, 值) 元組數組。
[ (鍵,值) , (鍵,值) , (鍵,值) ]
語法
list = dict.items()返回值
返回可遍歷的(鍵, 值) 元組數組。
常規用法
a = {"a": 1, "b": 2, "c": 3, "d": 4} print(a.items())輸出結果:
dict_items([('a', 1), ('b', 2), ('c', 3), ('d', 4)])
還可將key、value拆開來用
a = {"a": 1, "b": 2, "c": 3, "d": 4}for key,value in a.items():print("%s : %s" % (key, value))輸出結果:
a : 1
b : 2
c : 3
d : 4
總結
以上是生活随笔為你收集整理的Python_items()方法【详解】——Python系列学习笔记的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python中get()函数用法【详解】
- 下一篇: 【通俗易懂】理解Python中的if _