Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

setters and getters understanding

Hi everyone. I recently finished learning about the @property decorator which allows you to get any attribute via a method and the setter decorator or @(nameofattribute).setter which lets you set the attribute. In terms of my understanding, does the @property allow you to use dot notation and output an attribute which is the name of the method and the setter is used in order to change the value of the attribute like in the following examples bellow?

@property
def name(self): 
   return self.name



@name.setter 
def name(self,newname): 
   self.name = newname

1 Answer

Your understanding of "setter" is absolutely right, however "@property" means making a property which is a concept of OOP(Object-oriented programming). FYI: Check this.