r/Python • • 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

233 comments sorted by

View all comments

-19

u/baconcleaner Mar 19 '21

omg, seriously? What was wrong in using a dict to emulate a switch-case? Do we really need new statements at this point?

15

u/Jyan Mar 19 '21

It provides structural pattern matching https://www.python.org/dev/peps/pep-0622/ similarly to Scala -- it is extremely powerful and not easy to emulate.

12

u/nemec Mar 19 '21

Watch the video? This is structural pattern matching - some languages who have it build it upon their existing switch statement, but because Python doesn't have one, it seems like they've added a new switch statement when it's actually far more capable and full of features.

5

u/baconcleaner Mar 19 '21

ok I read more comments and I get it now: ITS NOT A SWITCH. The examples with pattern matching blow my mind. Can't wait to use it 2030 when autodesk maya will have it, for now lets continue with 2.7.

6

u/CashAccomplished7309 Mar 19 '21

If you don't like the feature, you don't need to use it.

I personally like it, coming from PHP.

→ More replies (3)

1

u/[deleted] Mar 19 '21

If you read the PEP, it's more or less doing the same thing, just with a clean syntax.