1. python中函数的嵌套定义与使用
    2. def fun1():
    3. def fun2():
    4. print('hello world')
    5. return fun2
    6. fun1()()
    7. 函数嵌套的三层用法:
    8. def fun1():
    9. print('我是fun1的函数体语句')
    10. def fun2():
    11. print('我是fun2的函数体语句')
    12. def fun3():
    13. print('Hello World!')
    14. return fun3
    15. return fun2
    16. a = fun1()
    17. b = a()
    18. b()
    19. # fun1中返回 fun2的方法名
    20. # fun1()就是调用函数 返回fun2的函数入口给变量a
    21. # a()就是调用函数fun2 返回fun3的函数入口给变量b
    22. # 最后调用b()
    23. Python中的函数闭包
    24. def fun1(x):
    25. def fun2(y):
    26. print(x+y)
    27. return fun2
    28. fun1(10)(20)
    29. //02\
    30. def fun1(x):
    31. def fun2(y):
    32. def fun3(z):
    33. print(x+y+z)
    34. return fun3
    35. return fun2
    36. fun1(10)(20)(30)
    37. # 最里面的函数可以得到外面层函数的局部变量