I would like to understand how the built-in function property
works. What confuses me is that property
can also be used as a decorator, but it only
The first part is simple:
@property
def x(self): ...
is the same as
def x(self): ...
x = property(x)
property
with just a getter.The next step would be to extend this property with a setter and a deleter. And this happens with the appropriate methods:
@x.setter
def x(self, value): ...
returns a new property which inherits everything from the old x
plus the given setter.
x.deleter
works the same way.