+ 1
What should be used in python to create switch statement?
Since switch can not be used there
2 ответов
+ 3
Either you write if, elif, else, or you store function names as values in a dictionary and access them via a 'case' key.
In most cases it doesn't seem to make a big difference.
https://code.sololearn.com/cBIJFJtahrZB/?ref=app
A dummy could look somewhat like this:
# functions are defined above here
functions = {
'1': function1,
'2': function2,
'3': function3,
...
}
inp = input()
functions[inp]()