手抄报 安全手抄报 手抄报内容 手抄报图片 英语手抄报 清明节手抄报 节约用水手抄报

如何将python中的字典变成列表

时间:2024-10-12 08:00:46

1、首先,新建一个空列表。代码示例如下:info = []

如何将python中的字典变成列表

2、然后,新建3个字典用于存储3个学生的各科成绩。代码示例如下:student_1 = {"Chinese":99,"Math":129,"English":145}student_2 = {"Chinese":98,"Math":139,"English":135}student_3 = {"Chinese":95,"Math":125,"English":130}

如何将python中的字典变成列表

3、接着用list.append() 的方法将存储学生1成绩的字典添加到列表中。代码示例如下:info.append(student_1)info

如何将python中的字典变成列表

4、如需将所有存储学生成绩的字典放入列表中,需要依次用list.append() 的方法添加。完整的代码如下:info = [柯计瓤绘]student_1 = {"Chinese":99,"Math":129,"English":145}student_2 = {"Chinese":98,"Math":139,"English":135}student_3 = {"Chinese":95,"Math":125,"English":130}info.append(student_1)info.append(student_2)info.append(student_3)info

如何将python中的字典变成列表
© 手抄报圈