【发布时间】:2022-11-19 11:15:02
【问题描述】:
class Student:
def __init__(self, name, major, gpa, onProbation):
self.name = name
self.major = major
self.gpa = gpa
self.onProbation = onProbation
Student1 = Student("Josh", "Business", 3.8, False)
Student2 = Student("Maya", "Accountancy", 2.5, True)
Student3 = Student("Dan", "Psychology", 1.2, True)
Student4 = Student("Keon", "Biomedical Engineering", 4.0, False)
Student5 = Student("Michelle", "Medicine", 3.7, False)
Student6 = Student("Joey", "Law", 4.0, False)
Students = ["Josh", "Maya", "Dan", "Keon", "Michelle", "Joey"]
我想弄清楚如何从列表中删除所有处于试用期的学生,所以如果我输入 print(Students),它只会给我未处于试用期的学生(Josh、Keon、Michelle 和 Joey )
【问题讨论】:
-
如果
Students是实际的Student对象列表,而不是字符串,那会容易得多。
标签: python python-3.x list class