闭包

代码:

def lazy_sum(*args):  // *args = 1,2,3,4,5
    def sum():
        ax = 0
        for n in args:
            ax = ax + n
        return ax
    return sum

lazy_sum 返回了 sum函数 相关参数与变量都保存在返回的函数中
每次调用 lazy_sum 返回的函数都是独特的

另,返回的函数并没有立刻执行,而是直到调用了f()才执行。。。

https://blog.csdn.net/sc_lilei/article/details/80464645

https://www.cnblogs.com/s-1314-521/p/9763376.html

最难理解的点

posted @ 2020-03-03 13:11  纯白的拉法达  阅读(77)  评论(0编辑  收藏  举报