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 Math

Hara Gopal K
PLUS
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
MOD
Chris Freeman
Treehouse Moderator 68,457 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.