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

In what kind of situations can class method be more useful than instance method?

I've read over the related questions but still am unclear about the advantages of class method than instance method though I understand that class method doesn't require to generate an instance to call the method like Bookcase.create_bookcase()

1 Answer

Steven Parker
Steven Parker
229,644 Points

One common use for a class method is when the method itself creates a new instance. That way, you can call it before having an instance, but get an instance back. This is used in some of the course lesson examples and challenges.

Kohei Ashida
Kohei Ashida
4,882 Points

Thank you, Steven! Now I feel I have to get common uses through further lessons and challenges.

I thought class methods didn't create new instances? Now I'm puzzled.

Steven Parker
Steven Parker
229,644 Points

They certainly can, if you write code for it (it's not automatic).

Thank you!