Python Magic Methods You Haven't Heard About
Python's magic methods - also known as dunder (double underscore) methods - can be used to implement a lot of cool things. Most of the time we use them for simple stuff, such as constructors (
__init__
), string representation (__str__
,__repr__
) or arithmetic operators (__add__
/__mul__
). There are however many more magic methods which you probably haven't heard about and in this article we will explore all of them (even the hidden and undocumented)!
Source: Python Magic Methods You Haven't Heard About, an article by Martin Heinz.