+ 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.

2nd Dec 2016, 5:14 PM
Dania Miller
Dania Miller - avatar
3 odpowiedzi
+ 3
Yes, of course: >>> def func1(): print(1) >>> def func2(): print(2) >>> func_list = (func1, func2) >>> func_list[0]() 1 >>> func_list[1]() 2
2nd Dec 2016, 5:29 PM
donkeyhot
donkeyhot - avatar
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.
2nd Dec 2016, 7:45 PM
Dania Miller
Dania Miller - avatar
0
Mind ... Blown !
31st Dec 2016, 9:18 PM
Hazard Sharp
Hazard Sharp - avatar