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

I dont understand magic methods in python. Could someone help me

I already watched the video on it but i still don't understand it

1 Answer

Steven Parker
Steven Parker
243,656 Points

They are not exactly "magic".

What's special about "magic methods" is that you don't call them directly. They get called automatically when you do things to their object, like perform math or make comparisons. They are easily identified by the two underscores both in front of and behind their name, like "__add__" or "__le__".

I now understand that part better but I don't understand how they are written and could I get an example of one written

Steven Parker
Steven Parker
243,656 Points

There are examples in the video you were watching!