1.匿名函数。
a = list(map(lambda x: x * x, [1, 2, 3, 4, 5, 6, 7, 8, 9]))
print(a) # [1, 4, 9, 16, 25, 36, 49, 64, 81]
f = lambda x: x * x
print(f) # <function <lambda> at 0x000002391B696048>
print(f(2)) # 4
def build(x, y):
return lambda: x * x + y * y
print(build(1, 2)) # <function build.<locals>.<lambda> at 0x000002391B6966A8>
f = build(1, 2)
print(f) # <function build.<locals>.<lambda> at 0x000002391B6966A8>
print(f()) # 5a