我被分配了这个任务:
我尝试做了这个:Write a one-line expression that transforms an f(x) function into f(x) +1. Hint: think about how a local frame binding for saved value of f, can be created without an assignment.
Example:
>>> f = lambda x: x*x >>> f(5) 25 >>> ---your one line expression--- >>> f(5) 26 >>> f, g = None, f >>> g(5) 26
我尝试做了这个:
k,f=f, lambda x: k(x)+1
这段代码可以运行,但是它使用了赋值操作 f=f
。有没有不用赋值操作的方法实现同样的功能呢?
我的老师告诉我在Python中有一个类似Scheme语言中的 let
函数,但她并没有告诉我们需要使用哪个函数。