“Case _” in Python Match Case Blocks In 30 Seconds

Liu Zuo Lin
Level Up Coding
Published in
2 min readApr 30, 2024

--

Match Case blocks were introduced in Python 3.10, and they are useful for writing conditional statements.

fruit = 'apple'

match fruit:
case 'apple':
print('pie')
case 'orange':
print('juice')

# pie

^ here, because fruit matches the case 'apple', the code inside the case block runs, and pie is printed. Note that if our fruit is…

--

--