[issue42128] Structural Pattern Matching (PEP 634)
Brandt Bucher
report at bugs.python.org
Fri Feb 19 18:56:56 EST 2021
Brandt Bucher <brandtbucher at gmail.com> added the comment:
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.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42128>
_______________________________________
More information about the Python-bugs-list
mailing list