我試圖創建一個列表,其中列出5個學生信息,然後傳遞給學生類。看起來我已經成功完成了這個任務,但現在我無法弄清楚如何訪問和修改列表中的任何以前添加的值。Python將列表傳遞給類,並試圖引用索引值
class Student:
def __init__(self, student_name, student_id, student_gpa, student_grade, student_time):
self.student_name = student_name
self.student_id = student_id
self.student_gpa = student_gpa
self.student_grade = student_grade
self.student_time = student_time
student_list = []
for i in range(5):
student_name = input("Please enter student's name: ")
student_id = input("Please enter student's ID number: ")
student_gpa = input("Please enter student's GPA: ")
student_grade = input("Please enter student's expected grade: ")
student_time = input("Please enter if student is a part or full time student: ")
student_list.append(Student(student_name, student_id, student_gpa, student_grade, student_time))
我怎麼可能會添加引用一個學生的名字和改變從什麼最初進入等級的選項?
要通過名稱訪問學生,最好使用字典,而不是列表。 – JohanL