主题
高阶函数
高阶:参数是函数、返回值是函数
常见的高阶函数:map、reduce、filter、apply
apply 在 Python2.3 被移除,reduce 被放在 functools 包中
推导式和生成器表达式可以替代 map 和 filter 函数
map(函数, 序列) 将序列中每个值传入函数,处理完成返回为 map 对象
python
number = list(range(11))
def square(x):
return x**2
print(list(map(square, number)))
print(dir(map(square, number)))
filter(函数,序列)将序列中每个值传入函数,符合函数条件的返回为 filter 对象