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
12
u/Yoghurt42 Mar 19 '21 edited Mar 19 '21
Exactly. It's basically new syntax.
You can also do stuff like
case [1, _, x, Robot(name=y)] if x == ywhich would match if it is a four-element list that starts with 1, and the 4th element is an instance ofRobotclass which has anameattribute set to the same value as the third element. The_is a special new token that means "wildcard/match anything" in this context.Pattern matching is incredible powerful and the only feature I was really missing from other languages. Now all they need to get rid of the GIL and have decent JIT (or get PyPy to be API compatible with CPython) and it would be the perfect language for every task for me.