class Screen(object):
@property def width(self): return self._width#起名加下划线是为了避免递归调用自己 @width.setter def width(self,value): self._width=value @property def height(self): return self._height @height.setter def height(self,value): self._height=value @property def resolution(self): return self.height*self.width
s = Screen() s.width=1024 s.height=768 print('resolution = ',s.resolution) if s.resolution == 786432: print('ok') else: print("not")
Sign in to make a reply
F盤裝滿基情
class Screen(object):
s = Screen() s.width=1024 s.height=768 print('resolution = ',s.resolution) if s.resolution == 786432: print('ok') else: print("not")