I’d like to set a variable based on an other variable. In my case
var1 can be “mean”, “sum” or “max” (input parsed from a gui). Based on these strings I want
to set (conditionally) another variable; like: if var1 is “mean” then
var2 = 2, if var1 = “sum” then var2=4, if var1 = “max” then var2 = 6.
What is the best way to do that (for a beginner)? If I use it in a if else procedure I
need to make the variables global to use them also outside the if?
Is there a recommended procedure?
Since python does not have a builtin switch-case statement, a pythonic way to do that is to use a dict:
You no longer need to think about the scope of the variable (eventhough it’s a good question to think about it !).