Is there a short way to call a function twice or more consecutively in Python? For example:
do()
do()
do()
maybe like:
3*do
You could define a function that repeats the passed function N times.
def repeat_fun(times, f):
for i in range(times): f()
If you want to make it even more flexible, you can even pass arguments to the function being repeated:
def repeat_fun(times, f, *args):
for i in range(times): f(*args)
Usage:
>>> def do():
... print 'Doing'
...
>>> def say(s):
... print s
...
>>> repeat_fun(3, do)
Doing
Doing
Doing
>>> repeat_fun(4, say, 'Hello!')
Hello!
Hello!
Hello!
Hello!