Special (magic) methods in Python

Question:

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.

Asked By: ibz

||

Answers:

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).

Answered By: David Cournapeau
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.