相关疑难解决方法(0)

如何重复一次功能n次

我正在尝试在python中编写一个函数,如:

def repeated(f, n):
    ...
Run Code Online (Sandbox Code Playgroud)

where f是一个带有一个参数的函数,n是一个正整数.

例如,如果我将square定义为:

def square(x):
    return x * x
Run Code Online (Sandbox Code Playgroud)

我打来电话

repeated(square, 2)(3)
Run Code Online (Sandbox Code Playgroud)

这将是3次,2次.

python higher-order-functions

5
推荐指数
3
解决办法
4万
查看次数

标签 统计

higher-order-functions ×1

python ×1