#__slots__=('width','height','resolution')
@property
def width(self):
return self._width
@width.setter
def width(self,width):
if not isinstance(width,int):
print('You should enter an integer')
else:
self._width=width
@property
def height(self):
return self._height
@height.setter
def height(self,height):
if not isinstance(height,int):
print('You should enter an integer')
else:
self._height=height
@property
def resolution(self):
return self._width*self._height
星月starnight
想用上slots,但是报错了。 class Screen(object):
去掉#就报错。 还有,为什么属性只能是self.width或self.__width,去掉‘’,用self.width,python就报错