编辑代码

class Rectangle:
    def __init__(self, width, height):
        self._width = width
        self._height = height

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

        @height.setter
        def height(self, height):
            if height <= 0:
                print("height")
            else:
                print('height')
                self_height = height

            @property
            def area(self):
                return self.width * self.height


a = Rectangle(3, 4)
print(a.width)
print(a.height)
a.width = -5
a.width = 5
a.height = 0
a.height = 2
print(a.area)
a.area = 12