Discuss / Python / 练习

练习

Topic source

xian_wen

#1 Created at ... [Delete] [Delete and Lock User]
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._width * self._height

你这样写虽然没错,但你忘了使用@property的出发点就是为了在setter中添加判断逻辑。要不然直接添加变量不好吗。


  • 1

Reply