公共和儿媳

Discuss / Python / note

thirty22

#1 Created at ... [Delete] [Delete and Lock User]

property 装饰器 全篇

[问]它是怎么实现的呢?

thirty22

#2 Created at ... [Delete] [Delete and Lock User]

class Screen(object):

    __slots__=('_height','_width','_resolution')

    @property

    def width(self):

        return self._width

    @width.setter

    def width(self, value):

        self._width = value

    @property

    def height(self):

        return self._height

    @width.setter

    def height(self, value):

        self._height = value

    @property

    def resolution(self):

        return self._width*self._height


  • 1

Reply