data = {
'action': 'list',
'type': '9',
'lang': 'zh_CN',
'f': 'json',
}
# 获取键名
for key in data.keys():
print(key)
# 输出 'action'
# 获取值
for val in data.values():
print(val)
# 输出 'list'
# 获取键值对
for item in data.items():
print(item)
# 输出 ('action', 'list')
python 遍历对象 获取键值对
python 遍历对象 获取键值对
data = {
'action': 'list',
'type': '9',
'lang': 'zh_CN',
'f': 'json',
}
# 获取键名
for key in data.keys():
print(key)
# 输出 'action'
# 获取值
for val in data.values():
print(val)
# 输出 'list'
# 获取键值对
for item in data.items():
print(item)
# 输出 ('action', 'list')