Python Lambda
方法一:使用默认参数
functions = []
for i in range(10):
functions.append(lambda x=i: print(x))
for f in functions:
f()
方法二:使用闭包
def create_printer(i):
def inner():
print(i)
return inner
functions = [create_printer(i) for i in range(10)]
for f in functions:
f()