Exercise: Lambda Functions

Questions for: Lambda Functions

What is a disadvantage of using lambda functions?
A:
They cannot be used in higher-order functions
B:
They can only contain a single expression
C:
They are less efficient than regular functions
D:
They cannot be assigned to variables
Answer: B
Lambda functions are limited to a single expression, which may be a disadvantage when more complex logic or multiple statements are required.
In Python, what is the purpose of the filter() function when used with lambda functions?
A:
To apply the lambda function to each element of an iterable
B:
To create a filter object based on the lambda function's condition
C:
To sort the elements of an iterable using the lambda function
D:
To map the lambda function to each element of an iterable
Answer: B
The filter() function is used to create a filter object that includes only the elements from an iterable for which the lambda function returns True.
Which of the following statements about lambda functions is correct?
A:
Lambda functions can have named parameters
B:
Lambda functions cannot be used in conjunction with higher-order functions
C:
Lambda functions support multiple lines of code
D:
Lambda functions are always more efficient than regular functions
Answer: A
Lambda functions can have named parameters, just like regular functions, allowing for greater flexibility in their usage.
What happens if a lambda function is assigned to a variable but not called immediately?
A:
It raises a syntax error
B:
It is stored as a reference to the function and can be called later
C:
It automatically executes the function
D:
It requires parentheses to be called later
Answer: B
Assigning a lambda function to a variable allows you to store it as a reference for later use. It doesn't automatically execute when assigned.
How is the syntax of a lambda function different from a regular function?
A:
Lambda functions use the keyword lambda, regular functions use def
B:
Lambda functions must have a return statement, regular functions may not
C:
Lambda functions can have multiple expressions, regular functions cannot
D:
Lambda functions require parentheses around parameters, regular functions do not
Answer: A
Lambda functions are defined using the lambda keyword, while regular functions are defined using the def keyword.
Ad Slot (Above Pagination)
Quiz