Talk

Supercharge your code with Python's 'match' statement

Friday, May 24

15:25 - 16:10
RoomPizza
LanguageEnglish
Audience levelIntermediate
Elevator pitch

When ‘match’ statement was added to Python 3.10, I thought it was a confusing feature. But after learning to use it correctly, it became my favourite new feature in Python. In this talk, we will learn how to use match to write much nicer, pythonic code. Then you will also fall in love with match.

Abstract

When ‘match’ statement was added to Python 3.10, I thought it was a confusing feature. I thought that it was just a fancy way of doing if/then/else statements. Why do we need a new feature just to make if/then/else a little simpler?

But I found out that my understanding was wrong. It is not a way to do if/then/else. It is something called structural pattern matching. That was a complicated word for me, but after reading up, the concept is not so difficult. It quickly became my favourite new feature in Python.

In this talk, we will take a deeper understanding into structural pattern matching and how it is related to match statement. With that understanding, we will learn how to use ‘match’ effectively. We will also look at some practical day to day situations where ‘match’ statement makes the python code much cleaner and easy to read.

By the end, you will understand why this feature was added into Python, how to use it effectively and fall in love with ‘match’ just like I did.

TagsCPython, Functional Programming, Clean Code
Participant

Siddharta Govindaraj

Hi, I’m Siddharta, a Python developer and trainer from India. I first encountered python in 2002, and it has remained my favourite programming language ever since. I was an early participant in BangPypers, India’s first Python community and a speaker at PyCon India 2009 & 2011. I am the author of the book “Test-Driven Python Development” published by Packt in 2015. Today I run the site playfulpython.com where I write about Python topics.