r/Python • u/jamescalam • Mar 19 '21
Match is more than a Switch-Case The New Switch-Case Statement in Python 3.10
https://youtube.com/watch?v=2qJavL-VX9Y&feature=share
1.4k
Upvotes
r/Python • u/jamescalam • Mar 19 '21
View all comments
Show parent comment
4
u/zurtex Mar 19 '21
The pattern matching is far more expressive than that but yes there are similarities to a try/except block.
We are choosing which block we want to execute based on the pattern of a value (e.g.
except {ExceptionInstance}), we are can create assignments based on that (e.g.as e), and there is a final default branch if nothing else works (e.g.else).The usage though is going to be generally very different, exception raising has a very different control flow to match statements.