my_dict_1 = {'name': 'Niuniu','Student ID': 1}
my_dict_2 = {'name': 'Niumei','Student ID': 2}
my_dict_3 = {'name': 'Niu Ke Le','Student ID': 3}
dict_list=[]
dict_list.extend([my_dict_1, my_dict_2, my_dict_3])
for index, value in enumerate(dict_list):
print(f"{value['name']}'s student id is {value['Student ID']}.")
注意append或者pop一次只能执行一个内容(list,对象,字符串,数字,字典等)3
然后enumerate返回列表的index和内容(就是字典)
lst = [1, 2]lst.append([3, 4]) # 添加整个列表,结果是嵌套print(lst) # [1, 2, [3, 4]] lst = [1, 2]lst.extend([3, 4]) # 展开加入每个元素print(lst) # [1, 2, 3, 4]

京公网安备 11010502036488号