Lambdas
An interesting way of making functions is through anonymous functions, also known as lambda expressions. Lambdas create a function that is essentially processed in-line, rather than giving it a name to be called later (hence, the anonymous part). This is useful when the normal def statement wouldn't necessarily work, such as within a list or as a function call's argument.
When using the normal def statement to create a function, the function is assigned a name and called from a different location, possibly multiple times; it also returns an object of some type. When using a lambda, the function itself is the returned object that can be given a name, if desired.
Lambdas look and work differently than regular functions. First, it is ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access