📜  python switch case 3.10 结构模式匹配——Python代码示例

📅  最后修改于: 2022-03-11 14:46:13.080000             🧑  作者: Mango

代码示例1
#From python 3.10 on, pattern matchin (switch case) has been added

def http_error(status):
    match status:
        case 400:
            return "Bad request"
        case 404:
            return "Not found"
        case 418:
            return "I'm a teapot"
        case 401|403|404:
              return "Not allowed"
        case _:
            return "Something's wrong with the internet"

#Source: https://docs.python.org/3/whatsnew/3.10.html