python中的switch...case...

"""
python12 中 引入了类似C和java的switch...case...的写法,
命名为 match...case...

作用:跟if...else...一样,只是match...case...用于判读不变的判断题
"""


def success(status):
    return f"status:{status},请求成功"


# 例如验证http状态码
def http_code(status: int = 200):
    match status:
        case 200:
            success(status)
        case 404:
            return "你的地址有误!"
        case _:
            return "你的status有误,请检查。"


if __name__ == "__main__":
    status = input("输入状态码:")
    http_code(int(status))

具体是python的第几个版本开始支持的,博主未知,只知道目前最新12.5已经支持。

你可能感兴趣的:(python,开发语言)