-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Description
Firstly, congratulation on PEP 634, I just want to suggest an enhancement for the "match" statement.
- When the matching against cases of pattern, there are some situations when there is no match.
- Using a cluster of "else" make it more readable compared with using a wildcard case.
- It's likewise in cases of the "if", "for", "try" statements, when conditions are not matching or when elements in a collection are not found, having the cluster of "else" in the above-mentioned statements make the code syntaxial readable to express what the Python program should.
For example , taken from PEP 636 , instead of :
match command.split():
case ["go", direction] if direction in current_room.exits:
current_room = current_room.neighbor(direction)
case ["go", _]:
print("Sorry, you can't go that way")the programmer have express a possible situation as :
match command.split():
case ["go", direction] if direction in current_room.exits:
current_room = current_room.neighbor(direction)
case ["go", _]:
print("Sorry, you can't go that way")
else :
print( f"Sorry, I don't understand what you mean by {command}.")I hope you got my point.
Metadata
Metadata
Assignees
Labels
No labels