Discuss / Python / 交作业

交作业

Topic source
    @property
    def width(self):
        return self._width

    @width.setter
    def width(self, value):
        # do something
        self._width = value

    @property
    def height(self):
        return self._height

    @height.setter
    def height(self, value):
        #do something
        self._height = value

    @property
    def resolution(self):
        return self._width*self._height

作业: class Screen(object): def init(self): self._width = 1024 self._height = 768 self._resolation = self._width * self._height @property def width(self): return self._width @width.setter def width(self,value1): self._width = value1 @property def height(self): return self._height @height.setter def height(self,value2): self._height = value2 @property def resolution(self): print('%d x %d' %(self._width, self._height))

In [78]: s = Screen()

In [79]: s.width = 100

In [80]: s.height = 100

In [81]: s.resolution 100 x 100


  • 1

Reply