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

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -