Jun-14-2019, 12:22 PM
Can also show a way that i like better.
funcs[user_choice]
I think looking at
Then it look like this.
funcs[user_choice]
()
as @buran show have done many times,but have tired to go away for using it.I think looking at
()
after a list can in some case be confusing,can also be using get()
to do error checking. Then it look like this.
def spam(): return('spam') def eggs(): return('eggs') def switch_case(user_choice): return { 'foo': spam(), 'bar': eggs(), }.get(user_choice, f'<{user_choice}> Not in Record') user_choice = input("foo or bar? ") print(switch_case(user_choice))
Output:foo or bar? foo
spam
foo or bar? bar
eggs
foo or bar? car
<car> Not in Record