How dunder methods rule Python under the hood
07-20, 12:30–13:00 (Europe/Prague), South Hall 2A

Python dunder methods – like __init__ – are sometimes referred to as “magic methods” but they are not!

They are just regular methods!

Functions that are associated with objects and that you can call with arguments.

The only thing is... Python also calls those functions behind the scenes in certain situations!

So, let us learn what that is all about.

In this talk aimed at beginners, we will see what “dunder methods” are and how they govern Python behind the scenes.

We will understand, for example, why the funny-looking method __init__ looks so funny and what its real purpose is.

Then, we will understand that all of the Python syntax really is governed by dunder methods, and thus, if you want your own classes and objects to interact with the Python syntax, all you need to do is implement the appropriate dunder methods.

For example, we will see how to use dunder methods to enable you to create a good string representation of your class, or how to define len on your own objects.

Although the talk is aimed at beginners, the audience is expected to know how to use the keyword class to create their own classes.

All materials can be accessed from this GH repo.

Expected audience expertise


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, writing on Twitter @mathsppblog, and giving workshops and courses.

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.

All materials can be accessed from this GH repo.

This speaker also appears in: