◐ Shell
clean mode source ↗

Message 387371 - Python tracker

I understand. I would just like to see something that won't give new Python pattern-matching users (read: everybody) the very painful first impression that this is a switch. Can we rework it like:

match input().split():
    case []:
        print("Got nothing!")
    case [first]:
        print(f"Got one word: {first}")
    case [first, last]:
        print(f"Got two words: {first} and {last}")
    case _:
        print("Got more than two words!")

Or something? (Pardon the example, I don't write many tutorials...)

I've seen too many knee-jerk reactions over the past weeks along the lines of "the new switch feature can't handle named constants!". My hope is something like the above might provide a more accurate, informative intro.