Python Tip #313 (of 365): Don't use match-case as a switch statement. Do this: i...
Trey Hunner ๐ @treyhunner@mastodon.social
Python Tip #313 (of 365):
Don't use match-case as a switch statement.
Do this:
if day in ("saturday", "sunday"):
return "weekend"
else:
return "weekday"
Not this:
match day:
case "saturday" | "sunday":
return "weekend"
case _:
return "weekday"
The match version adds indentation and doesn't even rely on the "structural" part of structural pattern matching.
More on this:
https://pym.dev/switch-case-in-python/
๐งต (1/2)