In [1]: def out_func():
...: def in_func():
...: print("in func")
...: return 100
...: return in_func
...:
...:
In [2]: f = out_func()
In [3]: print(type(f))
<class 'function'>
In [4]: print(f)
<function out_func.<locals>.in_func at 0x000001B9B99D6BF8>
In [5]: f()
in func
Out[5]: 100
In [6]:
带参数列表的返回函数
>>> def out_func(*args):
... def in_func():
... rst = 0
... for i in args:
... rst += i
... return rst
... return in_func
...
>>> f1 = out_func(1, 2, 3, 4, 5)
>>> f1()
15
>>> f2 = out_func(6, 7, 8, 9, 10)
>>> f2()
40