items() 函数以列表返回可遍历的(键, 值) 元组数组。
dict = {'Google': 'www.google.com', 'Baidu': 'www.baidu.com', 'taobao': 'www.taobao.com'}
# 将字典类型转换为可遍历的元组
print("字典值: %s" %dict.items())
# 遍历字典列表
for key,values in dict.items():
print(key,values)
items() 函数以列表返回可遍历的(键, 值) 元组数组。
dict = {'Google': 'www.google.com', 'Baidu': 'www.baidu.com', 'taobao': 'www.taobao.com'}
# 将字典类型转换为可遍历的元组
print("字典值: %s" %dict.items())
# 遍历字典列表
for key,values in dict.items():
print(key,values)