#i’m a beginner, bt want to try & prevent myself from making spaghetti code..

15 messages · Page 1 of 1 (latest)

silver cobalt
#

simply put, or @ least as simply as possible.. how does python’s: match statement work?

raven blade
silver cobalt
#

both, i suppose..

raven blade
#

Are you familiar with switch cases in other languages?

silver cobalt
#

can’t say i am

raven blade
#
action = input("input action")
if action == "open":
    ...
elif action == "close":
    ...
elif action == "move":
    ...
elif action == ...:
    ...
#

So, the match statement would make writing this a bit easier.

silver cobalt
#

i see..

raven blade
#

I can write a bit more, just need to craft the example.

#
action = input("input action: ")
match action:
    case "open":
        ...
    case "close":
        ...
    case ...
#

So this is just something really basic, but match is a lot more powerful than this.

#

If you're comfortable reading Python, then this PEP I think does a great job showing all of the neat features.

silver cobalt
#

ty!!

raven blade
#

I think the examples are pretty self contained and approachable, if you have questions about them, don't hesitate to ask.