【发布时间】:2022-08-18 17:33:05
【问题描述】:
为什么我们在 map、filter 和 reduce 函数中放置一个不带括号的函数?检查下面的代码
def func(n):
return n**2
print(list(map(func,[1,2,3,4,5,6,7]))) # Here in this line of code func is placed inside map function without parenthesis. Why it is not put in this way map(func(),[1,2,3,4,5,6,7])?
Output:
[1, 4, 9, 16, 25, 36, 49]
-
因为你传递的是函数,而不是执行的结果
标签: python function parentheses