@property lets you access a method like an attribute.
Useful for computed values, immutability, and encapsulation.
class Circle:
def __init__(self, r):
self._r = r
@property
def area(self):
return 3.14 * self._r**2
c = Circle(5)
print(c.area) # acts like attribute, not method
Output
78.5
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Answer:
@propertylets you access a method like an attribute.Output