Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

215
Views
SyntaxError: invalid syntax when using match case

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.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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"
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!