Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Object-Oriented Python Advanced Objects Math

Hara Gopal K
Hara Gopal K
Courses Plus Student 10,027 Points

magic methods, do we need them ?

i assume python uses these dunder methods internally and i hope we generally don't use them in our code. is this for understanding how python works in the background or do we need them in our code ?

1 Answer

Chris Freeman
Chris Freeman
Treehouse Moderator 67,995 Points

Good question! It is important to understand how python executes through the use of magic methods. In general, you won't need to create magic methods unless you are extending a build-in class to alter its standard behavior.

One magic method you use almost every time you create a new class is __init__. Another magic method __cmp__ might be needed if the class you are creating needs to be compared to other instances of this class.