【发布时间】:2021-08-04 02:13:39
【问题描述】:
为什么这段代码会失败:
OKAY = 200
NOT_FOUND = 404
INTERNAL_SERVER_ERROR = 500
match status:
case OKAY:
print('It worked')
case NOT_FOUND:
print('Unknown')
case INTERNAL_SERVER_ERROR:
print('Out of service')
case _:
print('Unknown code')
它会生成此错误消息:
File "/Users/development/Documents/handler.py", line 66
case OKAY:
^^^^
SyntaxError: name capture 'OKAY' makes remaining patterns unreachable
该错误消息是什么意思?如何修复代码以使其正常工作?
【问题讨论】:
标签: python switch-statement syntax-error python-3.10 structural-pattern-matching