What should be used in python to create switch statement? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What should be used in python to create switch statement?

Since switch can not be used there

8th Apr 2019, 2:45 PM
krishna sarda
krishna sarda - avatar
1 Answer
+ 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]()
8th Apr 2019, 2:55 PM
HonFu
HonFu - avatar