Python Programming - Lambda Functions
Exercise : Lambda Functions - General Questions
- Lambda Functions - General Questions
26.
When is it appropriate to use a lambda function?
Answer: Option
Explanation:
Lambda functions are suitable for short-term, specific tasks where a full function definition is not needed, providing a concise way to express functionality.
27.
What is the output of the following code?
numbers = [1, 2, 3, 4, 5]
squared = list(map(lambda x: x**2, numbers))
print(squared)
Answer: Option
Explanation:
The
map()
function applies the lambda function to each element of the list, squaring each number.
28.
What does the following lambda function do?
lambda x, y: x if x > y else y
Answer: Option
Explanation:
The lambda function returns the larger value between x and y using a conditional expression.
29.
In Python, what is the purpose of the
sorted()
function when used with a lambda function?
Answer: Option
Explanation:
The
sorted()
function is used to create a sorted list from the elements of an iterable, with sorting criteria defined by the lambda function.
30.
Which built-in function can be used with a lambda function to find the maximum value in an iterable?
Answer: Option
Explanation:
The
max()
function can be used with a lambda function to find the maximum value in an iterable based on the lambda function's criteria.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers