SyntaxError: invalid syntax when using match case [closed]

We Are Going To Discuss About SyntaxError: invalid syntax when using match case . So lets Start this Python Article.

SyntaxError: invalid syntax when using match case

  1. How to solve SyntaxError: invalid syntax when using match case [closed]

    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"

  2. SyntaxError: invalid syntax when using match case [closed]

    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"

Solution 1

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"

Original Author Joshua Voskamp Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment