Replacements for switch statement in Python? -
i want write function in python returns different fixed values based on value of input index.
in other languages use switch
or case
statement, python not appear have switch
statement. recommended python solutions in scenario?
you use dictionary:
def f(x): return { 'a': 1, 'b': 2, }[x]
Comments
Post a Comment