Skip to content

Update the "switch or case statement" section of the Design & History FAQ #116613

Closed as not planned
@RH-TLagrone

Description

@RH-TLagrone

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"

See PEP 634 and PEP 636 for more information.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions