You can use a dictionary to write a function like switch.
def switch1(x):
return {
'a': 1,
'b': 2,
}.get(x, 9) #default
switch1('a')
switch1('c')
switch2 = {'a':(1,2,3), 'b':4}
switch2.get('a', 9) #9 is the default
© 2024 OneMinuteCode. All rights reserved.