Python Programming - Lambda Functions
Exercise : Lambda Functions - General Questions
- Lambda Functions - General Questions
46.
What is the purpose of the
zip()
function when used with a lambda function?
Answer: Option
Explanation:
zip()
combines two iterables into pairs, allowing the lambda function to operate on corresponding elements.
47.
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.
48.
What does the following lambda function accomplish?
lambda x: len(x) if isinstance(x, str) else None
Answer: Option
Explanation:
The lambda function returns the length of a string and None for non-string values.
49.
What is the output of the following code?
numbers = [1, 2, 3, 4, 5]
filtered = list(filter(lambda x: x % 2 != 0, numbers))
print(filtered)
Answer: Option
Explanation:
The
filter()
function with the lambda filters out even numbers.
50.
What is the purpose of the
functools.partial()
function when used with a lambda function?
Answer: Option
Explanation:
functools.partial()
is used to create a partial application of a function, including lambda functions, by fixing certain arguments.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers