Python Programming - Lambda Functions
Exercise : Lambda Functions - General Questions
- Lambda Functions - General Questions
16.
In Python, what does the following code represent?
lambda x: x ** 2
Answer: Option
Explanation:
The lambda function
lambda x: x ** 2 represents a function that squares its input (multiplies it by itself).
17.
What is the purpose of the following code using the
enumerate() function and a lambda function?
my_list = [1, 2, 3, 4, 5]
result = list(map(lambda x: x[0] * x[1], enumerate(my_list)))
Answer: Option
Explanation:
The code uses
enumerate() to get tuples of index and element, and the lambda function multiplies the index (x[0]) by the element (x[1]).
18.
What is the result of the following Python code?
my_list = [1, 2, 3, 4, 5]
result = list(map(lambda x: x * 2, my_list))
print(result)
Answer: Option
Explanation:
The
map() function applies the lambda function lambda x: x * 2 to each element of my_list, doubling each value.
19.
Which built-in function can be used to find the minimum value in an iterable using a lambda function?
Answer: Option
Explanation:
The
min() function can be used with a lambda function to find the minimum value in an iterable based on the lambda function's criteria.
20.
How is a lambda function different from a regular function in terms of defining and using it?
Answer: Option
Explanation:
Lambda functions are defined using the
lambda keyword and are typically used for short-term, specific tasks without the need for a formal function definition.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers