装饰器@property作用:把一个方法变成一个属性进行调用
好处:使调用者写出简短代码
即检查了参数,又采用了直接的方式来访问类变量
例子如下:
利用@property **读写属性操作**
class Student(object):
@property
def score(self):
return self._score
@score.setter
def score(score, value):
if not isinstance(value, int): # 类型判断
raise ValueError('score must be an integer!')
if value