在__init__函数中判断赋值,为什么错了??
class Student(object): def __init__(self, name, score): self.name = name self.__score = score if self.__score>=80: self.grade = 'A' elif self.__score < 60: self.grade = 'C' else: self.grade = 'B' @property def score(self): return self.__score @score.setter def score(self, score): if score < 0 or score > 100: raise ValueError('invalid score') self.__score = score @property def grade(self): return self.grade s = Student('Bob', 59) print s.grade s.score = 60 print s.grade s.score = 99 print s.grade
can't set attribute