Python 字典(Dictionary) items(),pop(‘key‘)方法

描述

Python 字典(Dictionary) items() 函数以列表返回可遍历的(键, 值) 元组数组。

语法

items()方法语法:

dict.items()

参数

NA。

返回值

返回可遍历的(键, 值) 元组数组。

实例

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

tinydict = {
    
    'Google': 'www.google.com', 'Runoob': 'www.runoob.com', 'taobao': 'www.taobao.com'}

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

# 遍历字典列表
for key, values in tinydict.items():
    print(key, values)

print(tinydict.pop('Google'))
print(tinydict.pop('Runoob'))
print(tinydict.pop('taobao'))

在这里插入图片描述

dict.items() = (key+value)s

猜你喜欢

转载自blog.csdn.net/m0_51579041/article/details/142756682