You could use a dictionary:

def f(x):
    return {
        'a': 1,
        'b': 2,
    }[x]