dict1 = {'message': 'success',
'people': [
{'name': 'Sergey Ryzhikov', 'craft': 'ISS'},
{'name': 'Kate Rubins', 'craft': 'ISS'},
{'name': 'Sergey Kud-Sverchkov', 'craft': 'ISS'}
],
'number': 3}
# And then this will access it, by looping over the list and printing out all of the 3 names
for i in dict['people']:
print(i['name'])
迭代人员列表并选择要获取的dict属性
输出
你得给这本字典起个名字,像这样
这是一段非常简单的代码
我建议您使用
.get()
方法而不是方括号来访问字典中的值,以避免异常相关问题 更多 >
编程相关推荐