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.
Hara Gopal KCourses 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 ?
Chris FreemanTreehouse Moderator 67,636 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.