It doesn’t have switch or case statement which unlike other programming language. There are a few ways to simulate the effect. Here is official answer.
Function
1 2 3 4 5
defswitch(switcher, case, default=None): c = switcher.get(case, default) ifstr(type(c)) == "<class 'function'>": return c() return c
classSwitcher(object): defnumbers_to_methods_to_strings(self, argument): """Dispatch method""" # prefix the method_name with 'number_' because method names # cannot begin with an integer. method_name = 'number_' + str(argument) # Get the method from 'self'. Default to a lambda. method = getattr(self, method_name, lambda: "nothing") # Call the method as we return it return method()