1,python 解释器版本3.10以上可以使用如下
def dar(darling):
match darling:
case '400':
print(400)
case '401':
print(401)
case _:
print(404)
if __name__ == '__main__':
dar('400')
解释器版本,小于3.10 会报错SyntaxError: invalid syntax
2,所有版本
status = {
'400': lambda: stat400('400'),
'401': lambda: stat401(),
'404': lambda: print('我是404')
}
def stat400(x):
print('我是400' + x)
def stat401():
print('我是401')
if __name__ == '__main__':
status.get('404', lambda: print('未找到'))()
标签:__,python,else,switch,404,401,400,print,lambda
From: https://www.cnblogs.com/darling331/p/16609789.html