1.脚本 def add(a,b): return (a+b)def div(a,b,c): return (a/b-c)x = div(34,100,1023)y = add(24,x)print ("the result is %f" %y) print ("the result is %d" %y) 2.执行结果 备注 1.利用return可以将函数的值返回 2.%f返回浮点型 3.%d返回整形…
函数作为返回值高阶函数除了可以接收函数作为参数外,还可以把函数作为结果值返回. def lazy_sum(*args): def sum(): ax=0 for n in args: ax = ax + n return ax return sum f = lazy_sum(1,2,3,4,5) print f # <function sum at 0x02657770> # lazy_sum(1,2,3,4,5)返回的是一个指向求和的函数的函数名. # 在调用lazy_sum(1,2,3,4…