Dev HelpersOpen library
← Back

Expose a calculated property

Expose a calculated property. A self-contained example using the Python standard library.

Open this example in the interactive library

Source code

class Rectangle:
    def __init__(self, width, height):
        self.width, self.height = width, height
    @property
    def area(self):
        return self.width * self.height
print(Rectangle(3, 4).area)

Sample output

12