Recall & Review
beginner
What is a lambda function in Python?
A lambda function is a small anonymous function defined with the
lambda keyword. It can take any number of arguments but has only one expression.Click to reveal answer
beginner
Why do we use lambda functions instead of regular functions?
Lambda functions are used for short, simple functions that are needed temporarily, often as arguments to other functions, without the need to formally define a function using
def.Click to reveal answer
intermediate
Give an example of a situation where a lambda function is useful.
When sorting a list of tuples by the second item, you can use a lambda function as the key:
sorted(list_of_tuples, key=lambda x: x[1]). This avoids writing a separate function.Click to reveal answer
beginner
Can lambda functions have multiple expressions?
No, lambda functions can only have one expression. They return the result of that expression automatically.
Click to reveal answer
beginner
How do lambda functions help in making code more concise?
Lambda functions let you write small functions inline without naming them, which reduces the amount of code and makes it easier to read when the function is simple.Click to reveal answer
What keyword is used to create a lambda function in Python?
✗ Incorrect
The
lambda keyword is used to create anonymous functions in Python.Which of the following is true about lambda functions?
✗ Incorrect
Lambda functions are often used as arguments to other functions like
map, filter, or sorted.Why might you choose a lambda function over a regular function?
✗ Incorrect
Lambda functions are best for small, simple functions used temporarily, written inline.
Which of these is a valid lambda function syntax?
✗ Incorrect
The correct syntax uses
lambda followed by arguments, a colon, and a single expression.What will this code output?
print((lambda x: x * 2)(5))✗ Incorrect
The lambda function doubles the input 5, so the output is 10.
Explain in your own words why lambda functions are useful in Python.
Think about when you want a quick function without naming it.
You got /4 concepts.
Describe a real-life example where using a lambda function can make your code simpler.
Consider how you might sort a list of items by a specific part.
You got /4 concepts.