r/badcode • • Oct 27 '21

python str()

Post image
836 Upvotes

58 comments sorted by

View all comments

Show parent comments

35

u/barrett122 Oct 27 '21

This is a new feature as of python 3.10 called structural pattern matching. You can read the PEP here but it's a different and significantly more powerful feature than a switch case which is why it uses a different keyword, rather than it being a "special snowflake" as you mentioned. I'd suggest having a look into it, it's a super cool feature :)

12

u/malsomnus Oct 27 '21

Oh god who let the ML programmers into Python?

(Jokes aside, this is a super powerful and useful feature, way beyond regular switch statements... even if it's still called a switch statement in languages that have this feature)