Anonymous functions - the lambda keyword
The keyword lambda is used in Python to define anonymous functions, that is; functions without a name and described by a single expression. You might just want to perform an operation on a function that can be expressed by a simple expression without naming this function and without defining this function by a lengthy def
block.
Note
The name lambda originates from a special branch of calculus and mathematical logic, the -calculus.
For instance, to compute the following expression, we may use SciPy’s function quad
, which requires the function to be integrated as its first argument and the integration bounds ...
Get Scientific Computing with Python 3 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.