1.变量可以指向函数
<built-in function abs> >>> abs(-10) 10 >>> f=abs >>> f <built-in function abs>
2.函数名也是变量
>>> abs=10 >>> abs(-10) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'int' object is not callable
3.传入函数
既然变量可以指向函数,函数的参数能接收变量,那么一个函数就可以接收另一个函数作为参数,这种函数就称之为高阶函数。
>>> def add(x, y, f): ... return f(x) + f(y) ... >>> x=-5 >>> y=6 >>> f=abs >>> f(x)+f(y) #输出 11