What is a Python lambda function?
Why Interviewers Ask This
This is a classic screening question for Python roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.
Answer
A lambda function is a small, anonymous single-expression function defined with the lambda keyword. Syntax: lambda arguments: expression. Example: square = lambda x: x**2; square(5) returns 25. Lambdas are commonly used as quick inline callbacks: sorted(people, key=lambda p: p["age"]), filter(lambda x: x > 0, numbers), map(lambda x: x*2, numbers). Limitations: lambdas can only contain a single expression (no statements, no assignments, no docstrings). For anything non-trivial, use a regular def function instead — it is more readable and testable. In Python, lambdas are most appropriate for simple, one-line operations as arguments to higher-order functions.
Common Mistake
Don't just define the term — demonstrate that you understand when to use it and when not to. Showing awareness of trade-offs is what separates average from strong Python candidates.
Previous
What is the difference between is and == in Python?
Next
What is *args and **kwargs in Python?