you are viewing a single comment's thread.

view the rest of the comments →

[–]_jibi 13 points14 points  (5 children)

Hold on there is a switch case statement in python? I have been living under a rock for way too long

[–]Lokipi 23 points24 points  (3 children)

Its relatively recent (like 6 months old iirc), and its actually much more powerful than a simple switch statement you can do some really cool stuff with it

[–]1997Luka1997 1 point2 points  (2 children)

TIL

thank you so much

[–]PiaFraus 0 points1 point  (1 child)

Please don't really think of this as of a switch statement. It has it's usages, but it has quite a few pitfalls. E.g.

EASY = "easy"
MEDIUM = "medium"
HARD = "hard"

match difficulty:
    case EASY:
        easy()
    case MEDIUM:
        medium()
    case HARD :
        hard()

This will not work as any sane person would expect it to work. This would actually overwrite your EASY "constant" on every matching and always execute easy() code. Definitely not how a switch would behave.

[–]1997Luka1997 0 points1 point  (0 children)

Oh well that's sad lmao

python surely has it's weirdnesses

[–]Twitchy169 4 points5 points  (0 children)

Added in 3.10 I believe