The recommended path for Python 3.10 which is for 2021 which was  introduced with the match-case statement which will give access to a first-class implementation of a "switch" for Python. The example below should help you with clarity:
def f(x): 
    match x: 
            case 'a': 
                    return 1 
            case 'b': 
                    return 2 
            case _: 
                  return 0 # 0 is the default case if x is not found
The match-case statement is considerably more powerful than this simple example. You could also try using a dictionary:
 
def f(x): 
        return { 
              'a': 1, 
              'b': 2, 
          }[x]