53
votes

What are all the special (magic) methods in Python? The __xxx__ methods, that is.

I'm often looking for a way to override something which I know is possible to do through one of these methods, but I'm having a hard time to find how since as far as I can tell there is no definitive list of these methods, PLUS their names are not really Google friendly. So I think having a list of those here on SO would be a good idea.

1
These are often called "magic methods." That might help with google. - balpha
"Magic"? Where'd you get that? The Python documentation calls them "special method names". I've never seen them called "magic". Where did you see that? - S.Lott
@S.Lott No? Haven't you readen the docs? Haven't you readen the guide to them? - Alba Mendez
I don't understand why this is closed. The question is useful and constructive and the answer is supported by reference. There is nothing to debate or argue for this question. I don't see this violating any of the rules in help center. - ketorin
@ketorin: The reason why good questions like this get closed is because it is fun for people who have been granted shiny new powers to exercise them. - OCDev

1 Answers

52
votes

At the python level, most of them are documented in the language reference. At the C level, you can find it under the object protocol section (strictly speaking, you only have a subset here, though).