Skip to content

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

Description

@TLagrone-RH

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.

Activity

  1. pochmann3 commented on Mar 11, 2024

    @pochmann3
    Contributor

    The section [...] is out-of-date. Python has had the match statement since 3.10.

    Hmm? The section already does mention the match statement.

    And note the already existing issue #111307

  2. carljm commented on Mar 11, 2024

    @carljm
    Member

    I think there's a reasonable discussion to be had about whether the match statement should be more prominently featured in that section than a one-sentence aside, but it seems like that discussion is already happening on #111307; this issue is a duplicate.

  3. terryjreedy commented on Mar 19, 2024

    @terryjreedy
    Member

    My PR #115899 for #111307 has been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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