Why "match" function is recognized unknown in python 3.10

I am trying to use “match” in Thonny Editor Shell through python.org examples but receive an error that match is unknown!

File “”, line 2
match status:
^
SyntaxError: invalid syntax

What is the problem?

The error you show is at the beginning of line 2. I suspect that you have an unclosed ( on line 1.

Hello, Mr. Roberge

This a sample of code I used and received the same error in line 7

File “”, line 7
match color:
^
SyntaxError: invalid syntax

Also, match appears as an ordinary name not the internal python function.

While the origin code is thus:

Syntactically, I don’t see anything wrong. Semantically, it won’t work because color isn’t defined, so you’d want to do something like

color = Color.RED

before your match, but this is just a diversion from your actual issue, which I suspect is that whatever way you’re running your code is invoking Python 3.9 (or earlier). You could try something like:

from sys import version
print(version)

to see what version your code is actually running under.

Also, for future reference, please don’t post screenshots of code. Post the code as text. Discourse has special blocks for code, which you can access via the icon that looks like </>.

Hello, Kevin

the version is this:

3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:01:55) [MSC v.1900 32 bit (Intel)]

Well there you go, the problem is solved. You are not running Python 3.10, you are running 3.7.

Have you installed Python 3.10?

2 Likes

Hello, Steven

No, I have not installed. If it is necessary I will install the version 3.10, but which one of the versions, only 3.10 or one of the 3.10.xxxx series?

What about Thonny Editor? Does it respond to the 3.10 version?

You should use the highest version of the 3.10 series you can, as that will have the most bugs fixed.

In Thonny, go to the Tools menu, then Options, then the Interpreter tag. You can choose a different interpreter.

If you install Thonny 4.0, on Windows and Linux it will also install Python 3.10.

2 Likes

Thank you very much :slight_smile:

Hey,

I have the same problem but I am using version 3.11.1 - Dec 2022 release. Has Match been deprecated? not sure why is it not working. The code is simple, match is not recognised as a function
sentence = “test”
match sentence:
case “test”:
etcl

No, match has not been depreciated or removed.

It sounds like you are using an old version of Python, not 3.11 as you think. If you are using Thonny, you should follow the same instructions I gave and make sure that you are using the right Python interpreter. If you are using something else, you should tell us what you are using.

I have the same error on VS Code and i have changed the interpreter as well, but when i run:
from sys import version
print(version)

my output is:
3.9.17

Even though i have changed my interpreter on VS Code to the latest python version
Pls help me with this issue

This sounds like an issue with VS Code configuration. In my projects I can check the version of Python in the lower-right corner of the window–it tells me what version my project is currently using, and if I click on that it shows me the available python installations. What does yours say?