Re: match SyntaxError
Alan Gauld via Tutor <[email protected]> Tue, 9 Dec 2025 12:29:27 +0000
| Newsgroups | gmane.comp.python.tutor |
|---|---|
| Message-ID | <[email protected]> |
On 08/12/2025 21:50, Francis Belliveau via Tutor wrote:
> Running through tutorials and I cannot seem to code
> a "match" statement correctly.
Thanks for posting this because I didn't know about
the match statement type.
But that leads me to assume it's a very new addition
to Python. (looks like it was added in v3.10)
> val = 3
> match val:
> case 1:
> print("c1")
> case _:
> print("c_")
>
> I am getting:
> "SyntaxError: invalid syntax" for the line containing "match
> Python version is: 3.9.6 (default, Oct 17 2025, 17:15:53) [Clang 17.0.0 (clang-1700.4.4.1)] on Mac OS 26.1
3.9 doesn't support match, you need 3.10 or newer.
Your code worked ok on my 3.13 build. So my first
suggestion would be to upgrade your Python to the
latest version (3.14 I think)
Thanks for posting, I'd completely missed the addition
of match! :-)
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
_______________________________________________
Tutor maillist - To unsubscribe send an email to [email protected]
To unsubscribe or change subscription options:
%(web_page_url)slistinfo/%(_internal_name)s