can you do switch statements in python, like you can in c++?
7/2/2018 1:21:13 AM
Large Toad3 Answers
New AnswerNo you can not. But you can implement it by yourself. We can create a dictionary where the key is the case value and the key value is a function. def default(): print("default function") def first(): print("first function") def second(): print("second function") dict = { "first": first, "second": second } def switch(case): if case in dict: dict[case]() else: default() #Usage string = input() switch(string)
Learn Playing. Play Learning
SoloLearn Inc.
4 Embarcadero Center, Suite 1455Send us a message