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
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('未找到'))()