python property用法

2022-05-14 12:57:56 浏览数 (1)

class TestPropertyDecorator(object): def init(self, value): self.x = value

代码语言:javascript复制
@property
def x(self):
    return self._x

@x.setter
def x(self, value):
    if not (type(value) == int and 0 < value < 32):
        raise ValueError("TestProperty.x "
            "must be an integer between 0 and 32")
    self._x = value

0 人点赞