How do I call a function twice or more times consecutively?

后端 未结 9 1830
借酒劲吻你
借酒劲吻你 2020-12-05 00:02

Is there a short way to call a function twice or more consecutively in Python? For example:

do()
do()
do()

maybe like:

3*do         


        
9条回答
  •  时光取名叫无心
    2020-12-05 00:35

    My two cents:

    from itertools import repeat 
    
    list(repeat(f(), x))  # for pure f
    [f() for f in repeat(f, x)]  # for impure f
    

提交回复
热议问题