Lambda Functions Questions and Answers
Python Programming - Lambda Functions Questions with Answers explore anonymous functions used for short, inline operations. These Python Lambda Functions Questions are important for TCS, Wipro, and SSC exams focusing on functional programming
Lambda Functions
Showing 10 of
25 questions
11. Which statement about lambda functions is TRUE?
- They can contain multiple expressions
- They can have docstrings
- They can be used as arguments to higher-order functions
- They support statement-based logic
12. What will be the output: sorted([(1, 2), (3, 1), (5, 0)], key=lambda x: x[1])?
- [(5, 0), (3, 1), (1, 2)]
- [(1, 2), (3, 1), (5, 0)]
- [(5, 0), (1, 2), (3, 1)]
- Error
13. How can you square all numbers in a list using lambda?
- list(map(lambda x: x**2, numbers))
- list(lambda x: x**2, numbers)
- map(lambda x: x**2).list(numbers)
- numbers.map(lambda x: x**2)
14. What does this lambda do: lambda s: s[::-1]?
- Converts to uppercase
- Reverses the string
- Removes whitespace
- Splits the string
15. Which is the correct way to use lambda with filter to get numbers greater than 10?
- filter(lambda x: x < 10, numbers)
- filter(lambda x: x == 10, numbers)
- filter(lambda x: x > 10, numbers)
- filter(lambda x: 10, numbers)
17. How do you multiply each element by 2 using lambda and map?
- map(lambda x: x*2, numbers)
- map(lambda x: x**2, numbers)
- map(lambda x: x+2, numbers)
- map(lambda x: x/2, numbers)
18. What will this code return: list(filter(lambda x: len(x) > 3, ['cat', 'dog', 'elephant']))?
- ['cat', 'dog', 'elephant']
- ['elephant']
- ['cat', 'dog']
- []
20. What is the result of: max([(1, 2), (3, 1), (2, 4)], key=lambda x: x[0])?
- (1, 2)
- (3, 1)
- (2, 4)
- Error