Reputation: 23
If I have different functions with increasing numbers in their names how do I loop through them? For example:
def Func1():
something something
def Func2():
something something
def Func3():
something something
can I loop through them with a:
for i in range(1,4):
Upvotes: 1
Views: 6439
Reputation: 1121446
You can put the functions in a list and loop over that:
for func in [Func1, Func2, Func3]:
result = func()
Functions are first-class objects in Python, you can create (additional) references to them and call them from whatever reference you have.
Upvotes: 9