+ 1
Is it possible?
Is it possible to make lists or tuples with functions in them? If I defined to 3 functions: def func(): print(1) def func2(): print(2) def func3(): print(3) list = ("func", "func2", "func3") Could I make a list or tuple or something like that which could be accessed by input? Such as if the input is 1, it would do func, but if it was say 3, it would output func3? It would be greatly appreciated if you helped, thank you.
3 Respuestas
+ 3
Yes, of course:
>>> def func1():
print(1)
>>> def func2():
print(2)
>>> func_list = (func1, func2)
>>> func_list[0]()
1
>>> func_list[1]()
2
0
Okay, thank you! I probably seem dumb for asking that, but I was in school and didn't have time to figure it out.
0
Mind ... Blown !