Python 之闭包

# 闭包:在函数内部在定义一个函数,并且这个函数用到了外部函数的变量,那么将这个函数与这些变量统称为闭包。
# 实例如下:
def test1(num):
    def test1_in(num_in):
        return  num + num_in
    return test1_in


def test():
    print("----aaa----")

if __name__ == "__main__":
    test() # ----aaa----
    print(test) # <function test at 0x00768AE0>
    a = test
    print(a) # <function test at 0x00768AE0>
    a() # ----aaa----

    # 测试
    c = test1(10)
    print(c(1)) # 11
    print(c(2)) # 12
原文地址:https://www.cnblogs.com/yang-2018/p/10848011.html