Properties

@property turns a method into something you read like an attribute: r.area, with no parentheses. Use it for values computed from other fields, so they can never go stale.

A property can also have a setter. Then r.width = -1 runs your code, which can check the value and raise an error. The real value lives in self._width. The leading underscore means "private by convention": Python doesn't stop you touching it.

This is why Python code doesn't write get_width() and set_width(). Start with a plain attribute. If you later need checks, swap in a property and no caller has to change.

Notice that __init__ assigns self.width, so even the first value goes through the setter.

Run it, then try Rectangle(-2, 4).