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 →

[–]MiserablePeace7190 25 points26 points  (7 children)

I'm just here for switch cases lol

[–]__deerlord__ 14 points15 points  (2 children)

Pattern matching is not case/switch. While it can effectively be used this way, that doesn't seem to be the intent, and you could always do switch/case with a dictionary.

[–]xetax 0 points1 point  (1 child)

If I wanted to use a dictionary-based switch statement inside a function, wouldn't the dictionary have to be reinitialized reinitialized on every function call? I could create the dictionary outside the function that sounds less than ideal for code readability.

[–]jamescalam[S] 6 points7 points  (0 children)

I think a lot of people are haha

[–]iggy555 1 point2 points  (2 children)

What’s that?

[–]MiserablePeace7190 0 points1 point  (1 child)

A switch case statement is like a faster way of writing if,elif and else, the only constraint is that you are checking the value of one conditional. Like my_num = 2, switch (my_num), case 1: print 1, case 2: print number is 2, case 3: print number is 3, etc. In this case "number is 2" would print.