編程學習網 > 數據庫 > python中item函數是什么意思?
2021
06-09

python中item函數是什么意思?


這篇文章我們來學習一下關于python字典之中的python items函數的相關知識,items函數是什么意思,這個函數有什么作用都將會在接下來的文章之中得到解答。

描述

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

語法

items()方法語法:

dict.items()

參數

NA。

返回值

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

實例

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

# !/usr/bin/python

# coding=utf-8

dict = {'Google': 'www.google.com', 'Runoob': 'www.runoob.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'), ('Runoob', 'www.runoob.com')]

Google www.google.com

taobao www.taobao.com

Runoob www.runoob.com

以上就是這篇文章所講的全部內容,python中字典內置的items函數。希望所說的內容以及所舉的例子能對你有所幫助。想了解更多歡迎持續關注編程學習網

掃碼二維碼 獲取免費視頻學習資料

Python編程學習

查 看2022高級編程視頻教程免費獲取