What should be used in python to create switch statement?

Since switch can not be used there

4/8/2019 2:45:39 PM

krishnakumar sarda

2 Answers

New Answer


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]()