我一直在尝试使用匹配大小写而不是一百万个 IF 语句,但我尝试的任何操作都会返回错误:
match http_code:
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
我还尝试过测试我发现的示例,这些示例也会返回此错误,包括以下错误:
http_code = "418"
match http_code:
case "200":
print("OK")
case "404":
print("Not Found")
case "418":
print("I'm a teapot")
case _:
print("Code not found")
Run Code Online (Sandbox Code Playgroud)
我知道匹配案例对于 python 来说是相当新的,但我使用的是 3.10,所以我不确定为什么它们总是返回这个错误。
我是Python的新手,我正在尝试运行我的服务器但是我正在从我正在研究的项目中得到这个语法错误.
def find_shortest_path(start: GraphNode, end, path=[]):
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
为了清楚起见,我没有编写代码,我只是应该为项目设置样式,但我不知道如何在服务器中运行它而无法看到应用程序.