|
|

楼主 |
发表于 2019-9-14 22:06:16
|
显示全部楼层
我有一个发现
>>> def fun1():
print('123')
def fun2():
print('456')
return fun2
>>> fun1()
123
<function fun1.<locals>.fun2 at 0x00000248B4D7BEA0>
>>> type(fun1)
<class 'function'>
>>> fun1()()
123
456
我把return fun2()改为return fun2 这样就需要输入 fun1()(),才可以打印出123 456
只输入fun1()就会打印123 和<function fun1.<locals>.fun2 at 0x00000248B4D7BEA0>
你看下面这个,就是return后面只能跟函数名不能带()唉
def func1(x):
def func2(y):
return x * y
return func2
>>> func1(5)(6)
30
>>> def func1(x):
def func2(y):
return x * y
return func2()
>>> func1(5)(6)
Traceback (most recent call last):
File "<pyshell#97>", line 1, in <module>
func1(5)(6)
File "<pyshell#96>", line 4, in func1
return func2()
TypeError: func2() missing 1 required positional argument: 'y'
>>>
|
|