Special (magic) methods in Python

Python

Python Problem Overview


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.

Python Solutions


Solution 1 - Python

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionibzView Question on Stackoverflow
Solution 1 - PythonDavid CournapeauView Answer on Stackoverflow