Python Programming - Lambda Functions
Exercise : Lambda Functions - General Questions
- Lambda Functions - General Questions
21.
What happens if a lambda function has more parameters than arguments provided during its invocation?
Answer: Option
Explanation:
If a lambda function is defined with more parameters than provided during invocation, a
TypeError
is raised.
22.
What is the primary advantage of using a lambda function over a regular function?
Answer: Option
Explanation:
Lambda functions are often used for short, simple tasks due to their concise syntax, allowing them to be written in a single line.
23.
How does the
filter()
function work when used with a lambda function?
Answer: Option
Explanation:
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
.
24.
How can a lambda function be used to define a key for sorting a list of tuples by the second element?
Answer: Option
Explanation:
The lambda function
lambda x: x[1]
extracts the second element of a tuple, which is suitable for sorting based on the second element.
25.
What is the purpose of the
functools.reduce()
function when used with a lambda function?
Answer: Option
Explanation:
The
functools.reduce()
function is used to successively apply the lambda function to the elements of an iterable, accumulating values.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers