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

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

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

unit testing - How to mock PreferenceManager in Android? -