On 2020-06-24 23:14, Ethan Furman wrote:
On 06/24/2020 01:49 PM, Tim Peters wrote:
I too thought "why not else:?" at first. But "case _:" covers it in the one obvious way after grasping how general wildcard matches are.
"case _:" is easy to miss -- I missed it several times reading through the PEP.
Introducing "else:" too would be adding a wart (redundancy) just to stop shallow-first-impression whining.
Huh. I would consider "case _:" to be the wart, especially since "case default:" or "case anything:" or "case i_dont_care:" all do basically the same thing (although they bind to the given name, while _ does not bind to anything, but of what practical importance is that?) .[snip]
The point of '_' is that it can be used any number of times in a pattern: case (_, _): This is not allowed: case (x, x): When a pattern matches, binding occurs, and why bind to a name when you don't need/want the value?