def newfunc(n):
def myfunc(x):
return x + n
return myfunc
new = newfunc(100)
print(new)
输出:
<function newfunc.<locals>.myfunc at 0x000001FF3E5A0B70>
我们期望输出数字 200,但不在控制台中。
控制台中一切正常:
def newfunc(n):
def myfunc(x):
return x + n
return myfunc
new = newfunc(100)
new(200)
newfunc返回一个函数。
因此,打印输出是合适的。
要获取此函数的值,您需要调用它,例如这样
在这种情况下,将显示 200。