匿名函数需要在一行写完,如果返回值是多个,就要写成元组的格式
fun = lambda x:x+1 print(fun(5)) fun2 = lambda x,y,z:(x+y,y+z,z**2) print(fun2(5,6,7))
6 (11, 13, 49)
高阶函数满足下面一个条件
1)函数接收的参数是个函数名
2)函数返回值是个函数名
没有返回值的函数默认返回None,返回函数名就是其地址引用
ef fun1(func): print("This is my life") def fun2(string): print("I like %s" %string) fun1(fun2("Chris")) fun1(fun2) def func1(): print("This is new life") def func2(): print("This fun has return value") return func1 res = func2() res()
I like Chris This is my life This is my life This fun has return value This is new life