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 have any number of arguments but only one expression, which is returned automatically.Click to reveal answer
beginner
How does a regular function differ from a lambda function?
A regular function is defined using
def and can have multiple expressions and statements. It can also have a name and more complex logic, while a lambda is anonymous and limited to a single expression.Click to reveal answer
beginner
Can lambda functions have multiple statements?
No, lambda functions can only contain a single expression. They cannot have multiple statements or commands like regular functions.
Click to reveal answer
intermediate
When should you use a lambda function instead of a regular function?
Use lambda functions for short, simple operations that are used temporarily, such as in sorting or filtering. For more complex logic or reusable code, use regular functions.
Click to reveal answer
beginner
This function takes one argument
Example: Write a lambda function that adds 5 to a number.
add_five = lambda x: x + 5This function takes one argument
x and returns x + 5.Click to reveal answer
Which keyword is used to define a lambda function in Python?
✗ Incorrect
Lambda functions are defined using the
lambda keyword.What is the main limitation of lambda functions compared to regular functions?
✗ Incorrect
Lambda functions are limited to a single expression and cannot contain multiple statements.
Which of these is a valid lambda function that doubles a number?
✗ Incorrect
Option B is the correct syntax for a lambda function doubling a number.
When is it better to use a regular function instead of a lambda?
✗ Incorrect
Regular functions are better for multiple statements or complex logic.
What does this lambda function do?
lambda x, y: x + y✗ Incorrect
This lambda function takes two arguments and returns their sum.
Explain the differences between lambda functions and regular functions in Python.
Think about how you write each and when you use them.
You got /5 concepts.
Write a simple example of a lambda function and a regular function that both add 10 to a number.
Use lambda x: x + 10 and def add_ten(x): return x + 10
You got /3 concepts.