O'Reilly logo
  • Shobana Shanker thinks this is interesting:

Many classes also support additional features; for example, we can concatenate two strings (or any two sequences) using the + operator and find a sequence’s length using the built-in len() function. Such features are provided by special methods—these are like normal methods except that their names always begin and end with two underscores, and are predefined. For example, if we want to create a class that supports concatenation using the + operator and also the len() function, we can do so by implementing the __add__() and __len__() special methods in our class


Cover of Programming in Python 3: A Complete Introduction to the Python Language, Second Edition


The idea here, i guess, is to reuse what's already builtin python standard library as a feature and as a result extend that functionality rather than reinventing the wheel. I mean, sure you can add two custom objects of a custom class you created by writing a completely new method that doesn't reuse the builtin add method, but that means, you won't be using a + operator to add them, but you will just have to call that custom method by its custom name. Instead if you had reused add implementation, you could have in effect used a + operator just like how you would when you are adding two integers or concatenating two strings.