Le 22/12/2019 à 23:50, Stefan Ram a écrit :
Batuhan Taskaya <isidenti...@gmail.com> writes:
dont like this for _ in range(n): do() thing. Any suggestions?

   The participants of my beginner classes like to write:

n * do()

   for that purpose, but usuallythis does not work as intended!

   What would work sometimes is

eval( n * 'do();' )


or:

class repeatly_do:
    def __init__(self,n):
        self.n = n
    def __mul__(self,action):
        for _ in range(self.n):
            action()

def do():
    print('Here I am...')

repeatly_do(5) * do
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to