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, which is returned automatically.Click to reveal answer
beginner
How do you write a lambda function that adds 5 to its input?
You write it as
lambda x: x + 5. This means the function takes one argument x and returns x + 5.Click to reveal answer
beginner
Can a lambda function contain multiple expressions or statements?
No, a lambda function can only contain a single expression. It cannot have multiple statements or commands like loops or assignments.
Click to reveal answer
intermediate
How does a lambda function differ from a regular function defined with
def?A lambda function is anonymous (has no name) and is limited to one expression. A regular function can have multiple statements, a name, and more complex behavior.
Click to reveal answer
beginner
What is the output of this code?
add = lambda x, y: x + y print(add(3, 4))
The output is
7. The lambda function adds the two inputs 3 and 4 and returns the sum.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 a valid lambda function syntax?
✗ Incorrect
Option C is the correct syntax for a lambda function in Python.
What will this lambda function return?
lambda x: x * 2
✗ Incorrect
The lambda function multiplies the input by 2, so it returns double the input.
Can a lambda function have multiple statements inside it?
✗ Incorrect
Lambda functions are limited to a single expression and cannot contain multiple statements.
What is the main use of lambda functions?
✗ Incorrect
Lambda functions are mainly used for quick, small anonymous functions, often as arguments to other functions.
Explain what a lambda function is and how it differs from a regular function defined with
def.Think about the size and naming of the function.
You got /5 concepts.
Write a lambda function that takes two numbers and returns their product. Then explain how it works.
Use the format: lambda arguments: expression
You got /4 concepts.