'''内置函数
map()
zip()''''''返回1-10的奇数列表'''# for i in range(1,10,2):# print(i)# li = []# for i in range(1,10):# if i%2 ==1:# li.append(i)# print(i)# print(li)'''filter 过滤'''defis_odd(n):return n %2==1print(list(filter(is_odd,range(1,10))))'''
阶乘-->累积 循环,递归
reduce()函数会对参数序列中元素进行累积'''from functools importreducedefmulti(x, y):return x * y
print(reduce(multi,range(1,7)))# 6! [1,2,3,4,5,6]
匿名函数及高阶函数
deffunc_name(x):return x*x
func_name(1)'''匿名函数
匿名函数关键字 参数:表达式返回值
lambda x:x*x'''
f =lambda x:x*x
print(f(5))from functools importreduce# def multi(x, y):# return x * y# print(reduce(multi, range(1, 7))) # 6! [1,2,3,4,5,6]print(reduce(lambda x,y:x*y,range(1,7)))'''
匿名函数可以直接作为函数返回值'''deffx(i,j):returnlambda:i*j
# print(fx(6,6))
res = fx(6,6)# lambda :i*j = fx(6,6)print(res())'''
匿名函数当作参数'''deftest(a,b,func):
res = func(a,b)# res = a + breturn res
res = test(11,33,lambda x,y:x+y)print(res)'''
高阶函数
1.函数名可以作为参数输入
2.函数名可以作为返回值
只要满足条件之一-->高阶函数
map()
filter()
reduce()
'''