Operator overloading
Operator overloading was briefly talked about in Chapter 2, Data Types and Modules, in the Basic string operations section; now we will see how it works behind the scenes. Operator overloading simply means that objects that you create from classes can respond to actions (operations) that are already defined within Python, such as addition, slicing, printing, and so on. Even though these actions can be implemented through class methods, using overloading ties the behavior closer to Python's object model and the object interfaces are more consistent with Python's built-in objects; hence, overloading is easier to learn and use.
User-made classes can override nearly all of Python's built-in operation methods. These methods ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access