闭包可以理解为一种特殊的函数,其由两个函数嵌套组成:外函数与内函数 外函数返回值是内函数的引用
def 外层函数(参数): def 内层函数(): print("内层函数执行", 参数) return 内层函数 内层函数的引用 = 外层函数("传入参数") 内层函数的引用()
def func(a, b): def line(x): return a * x - b return line line = func(2, 3) print(line(5))