my_dict是一个列表,列表中包含了两个字典,for循环遍历每一个字典,get方法是字典的小助手,可以将字典中key对应的value打印出来。
code:
my_dict = [{"name": "ZhangSan", "age": "10", "city": "Chengdu"},{"name": "Lisi", "age": "11", "city": "Chengdu"}]
for dict_info in my_dict:
print(dict_info.get("name"))
#或者这样的写法
#print(dict_info["name"])
输出结果:
ZhangSan
Lisi