Skip to main content
EuroPythonCode of ConductLive 📹

Python objects under the hood

Room:
Wicklow Hall 1
Start (Dublin time):
Start (your time):
Duration:
180 minutes

Abstract

Have you ever heard of Python's magic methods? I am sorry, but they are not that “magic”! I agree they are really cool, but dunder methods (the name they usually go by) are just regular Python methods that you implement! And it is my job to help you learn about them.

Dunder methods are the methods that you need to implement when you want your objects to interact with the syntax of Python. Do you want len to be callable on your objects? Implement __len__. Do you want your objects to be iterables? Implement __iter__. Do you want arithmetics to work on your objects? Implement __add__ (and a bunch of others!). Just to name a few things your objects could be doing.

In this training, we will go over a series of small use cases for many of the existing dunder methods: we will learn about the way in which each dunder method is supposed to work and then we implement it. This will make you a more well-rounded Python developer because you will have a greater appreciation for how things work in Python. I will also show you the approaches I follow when I am learning about a new dunder method and trying to understand how it works, which will help you explore the remainder dunder methods by yourself.

For this training, you need Python 3.8+ and your code editor of choice.

Get the slides, exercises, and other resources on Github.

Tutorial(c)Python Internals


The speaker

Rodrigo Girão Serrão

Rodrigo has always been fascinated by problem solving and that is why he picked up programming – so that he could solve more problems. He also loves sharing knowledge, and that is why he spends so much time writing articles in his blog mathspp.com/blog, writing on Twitter @mathsppblog, and giving workshops and courses. You can also find his past talks here.

His main areas of scientific interest are mathematics (numerical analysis in particular) and programming in general (with a preference for the Python and APL languages), but Rodrigo also enjoys reading fantasy books, watching silly comedy movies and eating chocolate.



← Back to schedule