Python match case statement

Hi, I am new here and was trying to use the match case statement in python but am getting a synax error.

How to Use a match case Statement in Python 3.10 | LearnPython.com

When i type in the exact example to replit it’s throwing up a syntax error. Is it because python version is not 3.10 in replit? How can i check what version i have?

Hey @monduras welcome to the forums.

On the page you linked what code block are you referring to?

Here’s an example

command = 'Hello, World!'

match command:
  case 'Hello, World!':
    print('Hello to you too!')
  case 'Goodbye, World!':
    print('See you later')
  case other:
     print('No match found')

so like an if statement?

yea like an if else statement, it’s a new statement in 3.10

The default Python Repl template uses Python 3.8, to use Python 3.10, I recommend using this template:
python 3.10

3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.