python 字典(Dictionary) items()方法

您所在的位置:网站首页 字典setdefault python 字典(Dictionary) items()方法

python 字典(Dictionary) items()方法

2023-03-15 20:41| 来源: 网络整理| 查看: 265

描述

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) Output: ------------------------------------------------------------------------------------------- 字典值 : dict_items([('Google', 'www.google.com'), ('Runoob', 'www.runoob.com'), ('taobao', 'www.taobao.com')]) Google www.google.com Runoob www.runoob.com taobao www.taobao.com -------------------------------------------------------------------------------------------

转载地址:https://www.runoob.com/python/att-dictionary-items.html



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3