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())