@Scrazy
2016-02-15T08:38:06.000000Z
字数 273
阅读 792
python学习笔记
闭包的两个例子
ex1:
def line_conf():def line(x):return x ** 2 + 1return linemy_line = line_conf()print(my_line(5))运行结果26
list(map(lambda x: x ** 2 + 1, [5]))运行结果26
ex2:
def line_conf(a, b):def line(x):return a * x + breturn lineline1 = line_conf(1, 1)line2 = line_conf(4, 5)print(line1(6), line2(6))运行结果7 29
