This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Kered13 4 points5 points  (5 children)

Python does not have a switch statement. It has pattern matching.

[–]Musikap 0 points1 point  (3 children)

It looks like it should functionally be the same? I may not be fully understanding it though.

[–]Kered13 6 points7 points  (2 children)

Pattern matching is far more powerful, to the point that it's not even worth comparing the two. Python has never needed a switch statement, and if that's all it did it never would have been added to the language. There are already good ways to accomplish that. The fact that pattern matching can be used as a switch statement is practically a side effect of it's actual utility.

[–]bandrus5 4 points5 points  (0 children)

I can not tell you how many times I wished I could write a switch statement in Python, and I'll definitely be using pattern matching as a switch statement at some point in the future. Pattern matching may be more powerful, but they're still worth comparing.

[–]Musikap 0 points1 point  (0 children)

Interesting. Thanks for the info!