ss Student(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') if value < 0 or value > 100: raise ValueError('score must between 0 ~ 100') self._score = value s = Student() s.set_score(50) print(s.get_score())
class Student(object): def __init__(self): self._score = 0 @property def score(self): return self._score @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 s = Student() s.score = 60 print(s.score) class Screen(object): pass class Screen(object): @property def width(self): return self._width @property def height(self): return self._height @width.setter def width(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._width = value @height.setter def height(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._height = value @property def resolution(self): self._resolution = 1000 return self._resolution sc = Screen() print(sc.resolution) sc.height = 100 sc.width = 50 print(sc.height) print(sc.width)