class Student(object): # 有点类似其它高级语言的构造函数 def __init__(self,name,score): self.name = name self.score = score
def print_score(self): print("%s:%s"%(self.name,self.score))
def get_grade(self): if self.score >=90: return 'A' if self.score >=60: return 'B' return 'C' bart = Student("frank",100) print(bart.get_grade())