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 Object-Oriented Python Advanced Objects Constructicons

Kohei Ashida
Kohei Ashida
4,882 Points

Is my understanding correct on what is "decorator"?

Applying what Kenneth said in the video as follows to the coding in this video, the class method decorator modifies the expectation of what the class Bookcase would do to create a list of books. Is this correct?

A decorator is more or less a function that takes another function, does something with it, and then usually returns that function. The class method decorator, for example, does some modifying of the expectations of Python's object class. Which all of our classes are inherited from, so class methods can work how they do.

1 Answer

Steven Parker
Steven Parker
231,269 Points

You're right, and in particular a "@classmethod" decorator causes a method that would normally use a "self" parameter to refer to an instance to use a "cls" parameter to refer to the class itself instead.