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

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?


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.


Thank you very much :slight_smile: