Discuss / Python / 作业

作业

Topic source
class Screen(object):    @property    def width(self):        # 此处使用self._width        # 一是设为私有变量。二是表示这个是个属性,而非方法。        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._widths = Screen()s.width = 1024s.height = 768print('resolution =', s.resolution)if s.resolution == 786432:    print('测试通过!')else:    print('测试失败!')
class Screen(object):    @property    def width(self):        # 此处使用self._width        # 一是设为私有变量。二是表示这个是个属性,而非方法。        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._widths = Screen()s.width = 1024s.height = 768print('resolution =', s.resolution)if s.resolution == 786432:    print('测试通过!')else:    print('测试失败!')

  • 1

Reply