This question already has an answer here:
- Replacements for switch statement in Python? 32 answers
How could I reduce many "if" in my code?
For example:
example = "smth"
if example == "smth":
foo1()
elif example == "smth2":
foo2()
Is any other way to call object / function based on received data?
Example:
I recive "foo" - call function foo
I recive "calculate" - call function calculate
My lecturer suggested that I should create "dispatcher" but I don't know how
Aucun commentaire:
Enregistrer un commentaire