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 (s.resolution) assert s.resolution == 786432, '1024 * 768 = %d ?' % s.resolution
结果: 78336
assert的用法:如果没有得到786432这个值,会输入AssertionError: 1024 * 768 = 78336 ?
Traceback (most recent call last): File "C:/Users/air/AppData/Local/Programs/Python/Python35/ScreenProperty.py", line 22, in <module> assert s.resolution == 786432, '1024 768 = %d ?' % s.resolution AssertionError: 1024 768 = 78336 ?
我有个问题,要是想同时改宽和高该怎么办?我试过有问题呀
Sign in to make a reply
做自己别人都是浮云
结果: 78336
assert的用法:如果没有得到786432这个值,会输入AssertionError: 1024 * 768 = 78336 ?
Traceback (most recent call last): File "C:/Users/air/AppData/Local/Programs/Python/Python35/ScreenProperty.py", line 22, in <module> assert s.resolution == 786432, '1024 768 = %d ?' % s.resolution AssertionError: 1024 768 = 78336 ?