如果不用@property结果奇怪
class Student(object):
def __init__(self, name, score):
self.name = name
self.__score = score
@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
def grade(self):
pass
s = Student('Bob', 59)
print s.grade
print s.grade()
输出结果是 >
()
>是什么