There is no native switch statement in Python. However the following construct does the job (based on code here:
result = {
'case a': function1,
'case b': function2,
'case c': function3
}[value](parameters)
This is a code dictionary that matches 'value' with the keys and then executes (returns) the respective functions.
Another way is to use a sequence of if and elif statements
Comments
Post a Comment