在Python中,如何从raw_input添加字典的键和值?中号

时间:2018-10-07 14:48:12

标签: python python-2.7 dictionary

students = {}
name = input("Give me the student name(key): ")
grade = input("What is their Grade(value): ")

'(输入字典键=名称和值=等级 从字典中打印所有学生及其成绩”

2 个答案:

答案 0 :(得分:0)

students = {}
name = input("Give me the student name(key): ")
grade = input("What is their Grade(value): ")
students[name] = grade

您可以只使用students[key] = value

答案 1 :(得分:0)

下面的代码应该可以完成您的工作。有关如何添加到字典的详细信息,您可以参考上面共享的链接,也可以通过python文档查看。

students = {}
name = input("Give me the student name(key): ")
grade = input("What is their Grade(value): ")
students[name] = grade
print(students)