Supercharge your Python code with the match statement

siddharta


1

Vote

Description:

When 'match' statement was added to Python, I thought it was a confusing feature. But after learning to use it correctly, it quickly became my favourite new feature in Python. Many developers think 'match' is like a 'switch' statement in Java, but it is much more. In this talk, we will take a deeper understanding into structural pattern matching, and then you will also fall in love with 'match'

We will explore the following concepts:

  • What is structural pattern matching? How is it different from 'switch-case' in other languages like C++/Java?
  • Use cases where the match statement can supercharge your code
    • Working with functions that return different structures, eg: functional programming style
    • Working with data that can have different shape, eg: processing API responses in JSON format
    • Matching based on the type of object
    • Using match along with dataclasses
  • When NOT to use match
  • Some tricky things to watch out for

By the end of the talk, you will be able to understand the scope of 'match' feature along with examples of how to use it in a better way to write cleaner and more readable python code.

Prerequisites:

No prerequisites apart from understanding the basics of python

Content URLs:

I delivered this same talk in ChennaiPy last year, and again at PyCon Italia 2024 in May this year.

Link to my PyCon Italia talk - https://lnkd.in/gvqHbYHB

Slides and walkthrough of an earlier version of this talk that I delivered at ChennaiPy - https://www.playfulpython.com/supercharge-your-code-with-the-match-statement/

Speaker Info:

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 a speaker at PyCon India in 2009 & 2011 and most recently spoke at PyCon Italia 2024. I am the author of the book "Test-Driven Python Development" published by Packt in 2015.

Today I run the site https://www.playfulpython.com/ where I write about Python topics.

Speaker Links:

My talk at PyCon India 2009 - https://in.pycon.org/2009/talkfull/49/ My talk at PyCon India 2011 - https://in.pycon.org/2011/talks/24-creating-domain-specific-languages-in-python/ My Python Site - https://www.playfulpython.com/ Test Driven Python Development Book - https://www.amazon.com/Test-Driven-Python-Development-Siddharta-Govindaraj/dp/1783987928

Section: Core Python
Type: Talk
Target Audience: Intermediate
Last Updated: