列表生成式&生成器表达式
一、列表生成式
def func(): return [lambda x:i*x for i in range(4)] print([j(2) for j in func()])
结果:[6,6,6,6]
二、生成器表达式
def func(): return (lambda x:i*x for i in range(4)) print([j(2) for j in func()])
结果:[0,2,4,6]
def func(): return [lambda x:i*x for i in range(4)] print([j(2) for j in func()])
结果:[6,6,6,6]
def func(): return (lambda x:i*x for i in range(4)) print([j(2) for j in func()])
结果:[0,2,4,6]