BeginnerCoder

Lesson 21 — Properties

Computed attributes

@property makes a method act like a read-only attribute: you write c.area, not c.area(). The value is calculated every time you read it, so it always matches the other fields. Put @property on the line right above the def.

class User:
    def __init__(self, first, last):
        self.first, self.last = first, last
    @property
    def full(self):
        return self.first + " " + self.last

Why it matters: it hides logic behind a clean attribute-style API.

Want it another way?
Task

Add an area property to Circle (round(3.14159 * r * r, 2)) and print it.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.

Keep going with Python Intermediate

Ready for more? Optional paid resources that pick up where this lesson leaves off.

Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.