It is important to note that the lambda construction is only syntactic sugar in Python. Any lambda construction may be replaced by an explicit function definition:
parabola = lambda x: x**2+5 # the following code is equivalent def parabola(x): return x ** 2 + 5
The main reason to use this construction is for very simple functions when a full function definition would be too cumbersome.
lambda functions provide a third way to make closures as we demonstrate by continuing with the previous example, .
We use the function sin_omega from Section 7.6.1, Partial Application, to compute the integral of the sine function for various frequencies:
import scipy.integrate as si for iteration in range(3): print(si.quad(lambda x: sin_omega(x, iteration*pi), 0, pi/2.) )