OBJECTSChapter 8 · Objects and Classes
Special methods
Methods wrapped in double underscores, like __init__, are special methods (people call them dunder methods). Python calls them for you: __str__ when you print an object, __repr__ for a developer view, __eq__ for ==, __add__ for + and __len__ for len(). Defining them makes your objects feel built in.
Worked example
How it reads
a + breally callsa.__add__(b)- Without
__eq__,==only checks whether two names point at the same object __str__decides whatprintshows

Cloud tip: Define
__repr__ too: it is what you see for objects inside lists and in error messages.

