Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

The example using match keyword isn't complete #95986

Closed
Labels
docsDocumentation in the Doc dir
@Aljumaily

Description

@Aljumaily

Documentation

TheOther Key Features inWhat’s New In Python 3.10 contains the following code snippet:

from enum import Enumclass Color(Enum):    RED = 0    GREEN = 1    BLUE = 2match color:    case Color.RED:        print("I see red!")    case Color.GREEN:        print("Grass is green")    case Color.BLUE:        print("I'm feeling the blues :(")

However, the variablecolor is unknown, hence,NameError: name 'color' is not defined is shown. The solution is the declare acolor variable and assign it any of theColor enum values, like so:

from enum import Enumclass Color(Enum):    RED = 0    GREEN = 1    BLUE = 2color = Color.BLUEmatch color:    case Color.RED:        print("I see red!")    case Color.GREEN:        print("Grass is green")    case Color.BLUE:        print("I'm feeling the blues :(")

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


      [8]ページ先頭

      ©2009-2025 Movatter.jp