class Screen(object):
@property def width(self): return self._width @width.setter def birth(self,value): if isinstance(width, int) and width > 0: self._birth == value else: print('不对') @property def height(self): return self._height @height.setter def height(self,value): if isinstance(height,int) and height>0: self._height == value else: print('高错了') @property def resolution(self): print('resolution = ',self._height*self._width)
s = Screen() s._width = 1024 s._height = 768 print(s.resolution) assert s.resolution == 786432, '1024 * 768 = %d ?' % s.resolution
你的birth都没改
Sign in to make a reply
快乐的杀马特
class Screen(object):
test:
s = Screen() s._width = 1024 s._height = 768 print(s.resolution) assert s.resolution == 786432, '1024 * 768 = %d ?' % s.resolution