> For the complete documentation index, see [llms.txt](https://til.yulrizka.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://til.yulrizka.com/python/python3-match-case.md).

# python3 match case

since python 3.10, it support switch and case. it even can check on type and value

```
def check(v):
    match v:
        case "1", "2":
            print('both 1 2 is string')
        case "1", 2:
            print('1 is string 2 is int')
        case a, b:
            print(f'a={a}, b={b}')
        case a:
            print(f'a=a')

check(("1", "2"))
# both 1 2 is string

check(("1", 2))
# 1 is string 2 is int

check((1, None))
# a=1, b=None

check(1)
# a=a
```
