All courses › Intermediate Programming › @property
@property
@property turns a method into something that can be read like a plain attribute, without parentheses. It is useful when a value should be computed from other attributes, but used exactly as if it were stored directly.
makes
obj.method readable without ()Example
class Sirkel:
@property
def areal(self): return 3.14 * self.r**2
Sirkel(2).areal (no parentheses) gives the area.
Use
Practise object orientation for free →
@property for computed values — it keeps the interface simple even if the calculation changes later.← Encapsulation and polymorphism · Time complexity, O-notation →