網站首頁 編程語言 正文
items() 函數以列表返回可遍歷的(鍵, 值) 元組。
將字典中的鍵值對以元組存儲,并將眾多元組存在列表中。
如:
favorite_places = {'XiaoMing': 'TJL','XiaoQiang':'Amercia','Dongsheng':'Japan'}
print("數值:%s" % favorite_places.items())
for key,value in favorite_places.items():
print(key,value)
數值:dict_items([('XiaoQiang', 'Amercia'), ('Dongsheng', 'Japan'), ('XiaoMing', 'TJL')])
XiaoQiang Amercia
Dongsheng Japan
XiaoMing TJL
具體可以參考以下的例子,十分明顯
python3.5中的解釋:
def items(self): # real signature unknown; restored from __doc__
""" D.items() -> a set-like object providing a view on D's items """
pass
附:實例
dict = {'老大':'15歲',
'老二':'14歲',
'老三':'2歲',
'老四':'在墻上'
}
print(dict.items())
for key,values in dict.items():
print(key + '已經' + values + '了')
以上實例輸出結果為:
dict_items([('老大', '15歲'), ('老二', '14歲'), ('老三', '2歲'), ('老四', '在墻上')])
老大已經15歲了
老二已經14歲了
老三已經2歲了
老四已經在墻上了了
總結
原文鏈接:https://blog.csdn.net/hellfu/article/details/110875605
相關推薦
- 2022-05-20 jmeter連接數據庫The driver has not received any packets
- 2022-04-30 python的正則表達式和re模塊詳解_python
- 2023-01-18 解決CentOS下ImportError:?No?module?named?'_sqlite3'的問
- 2022-08-29 C語言八道筆試題精講帶你掌握指針_C 語言
- 2022-05-05 Python實現蟻群算法_python
- 2022-07-13 w2ui fixedBody 屬性
- 2022-06-29 C語言超詳細講解遞歸算法漢諾塔_C 語言
- 2022-07-25 python數據清洗中的時間格式化實現_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支