I've been trying to use a match case instead of a million IF statements, but anything I try returns the error:
match http_code:
^
SyntaxError: invalid syntax
I've also tried testing examples I've found, which also return this error, including this one:
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")
I'm aware that match cases are quite new to python, but I'm using 3.10 so I'm not sure why they always return this error.
Two possibilities: you've got a syntax error on an earlier line (count your opening ( and closing )!), or you're not using Python 3.10
As a commenter said, check your Python version: import sys;print(sys.version)
Here are my (as-expected) results running in 3.10:
Python 3.10.0 (tags/v3.10.0:b494f59, Oct 4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 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")
Out[1]: "I'm a teapot"