Closed as not planned
Closed as not planned
Description
Documentation
The section Why isn't there a switch or case statement in Python? of the Design and History FAQ is out-of-date. Python has had the match
statement since 3.10.
I propose updating Why isn't there a switch or case statement in Python? to read:
Starting in Python 3.10, there is!
The
match
statement is used for pattern matching:def http_error(status): match status: case 400: return "Bad request" case 404: return "Not found" case 418: return "I'm a teapot" case _: return "Something's wrong with the Internet"
This proposed content emulates Why can’t I use an assignment in an expression? (another section in the same document), which I believe is an effective (and already-established) template for addressing a similar issue.