Module 10 Overview
Module 10: Magic Methods (or “Dunder” methods, short for Double UNDERscore) allows you to define how your objects behave with built-in Python operators and functions.
Have you ever wondered why you can use + to add numbers and concatenate strings? Or why len() works on lists, tuples, and strings? This is achieved through magic methods.
Learning Objectives
Section titled “Learning Objectives”By the end of this module, you will be able to:
- Customize how your objects are printed using
__str__and__repr__. - Implement Operator Overloading to allow using
+,-,*with your objects. - Make your objects behave like lists or dictionaries using Container Emulation.
- Understand the Python Data Model and how the interpreter interacts with your classes.
Module Contents
Section titled “Module Contents” String Representation Controlling the output of print() and the console.
Operator Overloading Customizing math operators like + and -.
Container Emulation Making your objects iterable and indexable.