Build a Computed Full Name
Intermediate · Write the code · from Python @property: Getters, Setters, and Computed Attributes
From the lesson: Python @property: Getters, Setters, and Computed Attributes
Imagine a thermostat on your wall. You set the temperature to 72°F and the system heats your house. But what if someone sets it to 5000°F? The house wouldn't literally reach that temperature, but your heating system would run forever trying. A smart thermostat would reject that value immediately.
Read the lessonCreate a class Person with first_name and last_name as regular attributes. Add a read-only computed property full_name that returns them joined with a space. Create Person('John', 'Doe'), print full_name, then change last_name to 'Smith' and print full_name again.
# Create the Person class with a computed full_name property
More @property exercises
- Create a Read-Only Name PropertyBeginner
- Add Age Validation with a SetterIntermediate
- Fix the Infinite RecursionIntermediate
- Predict the Temperature OutputIntermediate
- Refactor to Use @propertyAdvanced
All Python exercises · 50 practice problems · Object-Oriented Programming quiz