Sure, here’s a simple example of a switch statement in Python:
pythonCopy code<code>def switch_case(argument): switcher = { 1: "One", 2: "Two", 3: "Three", 4: "Four", 5: "Five" } return switcher.get(argument, "Invalid input") # Example usage: print(switch_case(2)) # Output: Two print(switch_case(6)) # Output: Invalid input </code>
This code defines a function switch_case()
that takes an argument and returns a value based on a switch-like structure using a dictionary in Python. The function maps input integers to corresponding strings. If the input is not found in the dictionary keys, it returns “Invalid input”.