函数式编程

函数式编程是一种思维,闭包只是其一种体现

匿名函数

#例如 x+y

#普通函数
def add(x,y):
  return x+y

#匿名函数
lambda x,y:x+y

三元表达式

# x,y   x大于y,取x 否则,取y
# x > y ? x:y  (其他语言中)
# x if x > y else y #python中
#条件为真时返回的结果 if 条件判断 else 条件为假时的返回结果 
x = 1
y = 4
r = x if x > y else y
print(r) #4

map类

map常用方法

reduce 连续计算,连续计算,连续调用lambda

map/reduce编程模型 映射 归纳 并行计算 函数式编程

filter 过滤

Last updated

Was this helpful?