Summary of Magic Methods
Get a summarized overview of magic methods in Python.
We'll cover the following...
We can summarize the concepts we have learned in the form of a cheat sheet like the one presented as follows. For each action in Python, the magic method involved is presented, along with the concept that it represents:
Magic methods and their behaviour in Python
Statement | Magic Method | Behavior |
|
| Subscriptable object |
|
| Context manager |
|
| Iterable object Sequence |
|
| Dynamic attribute retrieval |
|
| Callable object |
The best way to implement these methods correctly (and to know the set of methods that need to be implemented together) is to declare our class to implement the corresponding class following the ...