this is the error my terminal gives me when i try to use the match case statement in python 3.12.4 on vscode:
python -u "/Users/Riccardo/Desktop/Coding/Python/Programmi Python/prove.py"
Riccardo@ipicchiop Coding % python -u "/Users/Riccardo/Desktop/Coding/Python/Programmi Python/prove.py"
File "/Users/Riccardo/Desktop/Coding/Python/Programmi Python/prove.py", line 2
match status:
^
SyntaxError: invalid syntax
Riccardo@ipicchiop Coding % python3 --version
Python 3.12.4
Riccardo@ipicchiop Coding %
def http_error(status):
match status:
case 200:
return "OK"
case 400:
return "Bad request."
case 404:
return "Page not found"
case 500:
return "Internal Server error"
case _:
return "Something went wrong"
print(http_error(400))
this was the used code that i found on internet
New contributor
user25832629 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.