你想把学生名单上的所有学生都带走。所以在for循环中使用它。另外,您在方法中正确地封装了通过/失败标准的逻辑,因此请使用它。
我想这是你想要的代码:
def failed(list_of_students):
failed_students = []
for student in list_of_students:
if not student.passes():
failed_students.append(student.name)
return failed_students
更高级的方法是使用列表理解:
def failed(list_of_students):
return [student for student in list_of_students if not student.passes()]
它更具Pythic,但对于C语言或Java背景的初学者来说,我更难理解。