Python基础(@property)
class Point(object): # def get_score(self): # return self.score # def set_score(self,value): # if not isinstance(value,(int)): # raise ValueError('score must be an integer!') # elif value < 0 or value > 100: # raise ValueError('score must between 0 ~ 100!') # self.score = value @property def score(self): return self._score#使用@property,self的属性前面加上_,@score.setter是@加属性加.setter @score.setter def score(self,value): if not isinstance(value,(int)): raise ValueError('score must be an integer!') if value < 0 or value > 100: raise ValueError('score must between 0 ~ 100!') self._score = value p1 = Point() #p1.set_score(30) #print(p1.get_score()) p1.score = 30 print(p1.score)
https://edu.51cto.com/lecturer/11857712.html 星星课堂web前端系列课程
https://edu.51cto.com/course/25959.html js设计模式课程
https://edu.51cto.com/course/23133.html js进阶与组件化实战课程
https://edu.51cto.com/course/24757.html jquery课程
https://edu.51cto.com/course/22392.html js基础与入门课程
https://edu.51cto.com/course/26063.html vue零基础入门课程
https://edu.51cto.com/course/22393.html xhtml与css基础入门课程