In my understanding, we have a function that needs two arguments, but it has been defined with only one! However, the first time we use it in mydoubler = myfunc(2), it assigns the argument(2) to variable n, but the second time we use it in print(mydoubler(11), it uses the argument(11) to set the value of the variable a! Why is that? Does Lambda work like a recursive function? def myfunc(n): return lambda a : a * n mydoubler = myfunc(2) print(mydoubler(11))推荐答案基本上会发生什么: mydoubler = myfunc(2)实际上与编写 mydoubler = lambda a:a * 2 这样做的原因是 myfunc(2)返回 lambda a:a * 2 所以现在 mydoubler = lambda a:a * 2 然后,当调用 mydoubler(11)时,它仅返回 11 * 2 Then when mydoubler(11) is called, it simply returns 11 * 2 这篇关于有关Python中的Lambda函数的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-25 06:45