【Python3】匿名函数

匿名函数是不需要显式的指定函数

#这段代码
def calc(n):
    return n**n
print(calc(10))
 
#换成匿名函数
calc = lambda n:n**n
print(calc(10))

匿名函数主要是和其它函数搭配使用,如下

res = map(lambda x:x**2,[1,5,7,4,8])
for i in res:
    print(i)

#输出
1
25
49
16
64
原文地址:https://www.cnblogs.com/shengxinjack/p/7743397.html