대충~ 3.10 부터 추가되었다는 이야기

 

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"
Note the last block: the “variable name” _ acts as a wildcard and never fails to match. If no case matches, none of the branches is executed.

You can combine several literals in a single pattern using | (“or”):

case 401 | 403 | 404:
    return "Not allowed"

class Point:
    x: int
    y: int

def where_is(point):
    match point:
        case Point(x=0, y=0):
            print("Origin")
        case Point(x=0, y=y):
            print(f"Y={y}")
        case Point(x=x, y=0):
            print(f"X={x}")
        case Point():
            print("Somewhere else")
        case _:
            print("Not a point")

[링크 : https://docs.python.org/ko/3.10/tutorial/controlflow.html#match-statements]

[링크 : https://okeybox.tistory.com/395]

[링크 : https://leapcell.io/blog/ko/python-eseo-switch-muneul-jakseonghaneun-bangbeop-2025-switch-case-yeeje]

[링크 : https://www.bangseongbeom.com/python-switch-case]

 

PEP - Program Enhance Proposal

[링크 : https://wikidocs.net/7896]

 

2020년에 작성되었고, 3.10 버전에 추가됨.

PEP 636 – Structural Pattern Matching: Tutorial
Author: Daniel F Moisset <dfmoisset at gmail.com>
Sponsor: Guido van Rossum <guido at python.org>
BDFL-Delegate:
Discussions-To: Python-Dev list
Status: Final
Type: Informational
Created: 12-Sep-2020
Python-Version: 3.10
Post-History: 22-Oct-2020, 08-Feb-2021
Resolution: Python-Committers message

[링크 : https://peps.python.org/pep-0636/]

 

아니 본인이 2006년에 썼다가 reject 했어?

PEP 3103 – A Switch/Case Statement
Author:Guido van Rossum <guido at python.org>
Status:Rejected
Type:Standards Track
Created:25-Jun-2006
Python-Version:3.0
Post-History:26-Jun-2006

[링크 : https://peps.python.org/pep-3103/]

'Programming > python(파이썬)' 카테고리의 다른 글

python simsimd  (0) 2025.08.28
python 원하는 버전 설치 및 연결하기  (0) 2025.08.26
pip 패키지 완전 삭제하기  (0) 2025.08.13
pip install cmake build multi core support  (0) 2025.08.13
python 빌드 정보  (0) 2025.08.04
Posted by 구차니