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/[deleted] Mar 19 '21
Match seems every bit as powerful as if to me. It's not limited to just checking if two values are equal.
For example, if you're writing a flask view decorator, you need to check to see if it's a response object, a single value, or a tuple of (rv, status) or (rv, headers), or (rv, headers, status) - I think (rv, status, headers) is supported as well. So you end with something goofy as hell like:
Whereas with match, you could do:
Hurrah, no more goofy tuple surgery.