Tutorials

What is the magic of magic methods in the Python language?

Thursday, May 15th, 2025 9 a.m.–12:30 p.m. in Room 310/311

Presented by

Paweł Żal

Experience Level:

Some experience

Description

Welcome to this tutorial on Python's magic methods, often underestimated or overlooked in programming practice. And yet, magic methods make it easy to write code that implements often very complex algorithms in a readable way.

Python allows you to equip created classes with special methods, also known as magic methods or dunder methods. To recognize a special method, you should know that it is a method whose name begins and ends with a double underscore. But it's not the name that their magic lies in, because these methods have a special meaning for Python.

Python calls magic methods in response to fundamental operations, such as creating class instances, indexing sequences, comparing objects, managing attribute access, and more, so knowing how to create them is fundamental for any Pythonista.

During this tutorial, you’ll: * Find out what Python magic methods are, * Understand the magic behind Python magic methods, * Learn how to create and use magic methods, * Customize various behaviors of classes using magic method. * Talk about some interesting non-trivial magic methods.

To fully benefit from this tutorial, you should be familiar with object-oriented programming in Python.

This tutorial will have classroom exercises, post class homeworks as well as complimentary readings. All the presentation, code, exercises will be shared in advance and the solutions of the exercise will be shared after the tutorial is completed.

Search