Python 字典 items 方法

2022-07-05 01:27:10 字數 733 閱讀 3259

python 字典 items() 方法以列表形式(並非直接的列表,若要返回列表值還需呼叫list函式)返回可遍歷的(鍵, 值) 元組陣列。

items() 方法語法:

d.items()

以列表形式返回可遍歷的(鍵, 值) 元組陣列。

以下例項展示了 items() 方法的使用方法:

# !/usr/bin/python3

d =

print("字典值 : %s" % d.items())

print("轉換為列表 : %s" % list(d.items()))

# 遍歷字典列表

for key, value in d.items():

print(key, value)

以上例項輸出結果為:

字典值 : d_items([('google', 'www.google.com'), ('taobao', 'www.taobao.com'), ('runoob', 'www.runoob.com')])

轉換為列表 : [('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 字典 items 方法以列表形式 並非直接的列表,若要返回列表值還需呼叫list函式 返回可遍歷的 鍵,值 元組陣列。items 方法語法 1d.items 以列表形式返回可遍歷的 鍵,值 元組陣列。以下例項展示了 items 方法的使用方法 12 3456 78910 usr bin...

Python 訪問有序字典中的items

最近在看python的指令碼,遇到了 dictionary items 的用法,初學不太清楚,做個筆記 一 首先說說items 函式的作用 items 函式以列表返回可遍歷的 鍵,值 key,values 元組陣列,最基本的語法為dict.items 二 寫個例項 import collection...

Python3 字典中的items 函式

python3 字典中的items 函式 作業系統 windows 10軟體版本 python 3.6.2 amd64編 者 wordzzzz 一 python2.x中items 和之前一樣,本渣渣先貼出來python中help的幫助資訊 help dict.items help on method...