Lambda Functions Questions and Answers

Practice Mode
Showing 10 of 25 questions
Q11
Which statement about lambda functions is TRUE?
  • A They can contain multiple expressions
  • B They can have docstrings
  • C They can be used as arguments to higher-order functions
  • D They support statement-based logic
Answer: Option C
Explanation: Lambda functions can be used wherever function objects are required
Q12
What will be the output: sorted([(1, 2), (3, 1), (5, 0)], key=lambda x: x[1])?
  • A [(5, 0), (3, 1), (1, 2)]
  • B [(1, 2), (3, 1), (5, 0)]
  • C [(5, 0), (1, 2), (3, 1)]
  • D Error
Answer: Option A
Explanation: The lambda function extracts the second element of each tuple for sorting
Q13
How can you square all numbers in a list using lambda?
  • A list(map(lambda x: x**2, numbers))
  • B list(lambda x: x**2, numbers)
  • C map(lambda x: x**2).list(numbers)
  • D numbers.map(lambda x: x**2)
Answer: Option A
Explanation: map() with lambda can transform each element in an iterable
Q14
What does this lambda do: lambda s: s[::-1]?
  • A Converts to uppercase
  • B Reverses the string
  • C Removes whitespace
  • D Splits the string
Answer: Option B
Explanation: String slicing with [::-1] reverses a string
Q15
Which is the correct way to use lambda with filter to get numbers greater than 10?
  • A filter(lambda x: x < 10, numbers)
  • B filter(lambda x: x == 10, numbers)
  • C filter(lambda x: x > 10, numbers)
  • D filter(lambda x: 10, numbers)
Answer: Option C
Explanation: filter() keeps elements where lambda returns True
Q16
What is the output of: (lambda x: x if x > 0 else -x)(-5)?
  • A -5
  • B 5
  • C 0
  • D Error
Answer: Option B
Explanation: This lambda returns absolute value of a number
Q17
How do you multiply each element by 2 using lambda and map?
  • A map(lambda x: x*2, numbers)
  • B map(lambda x: x**2, numbers)
  • C map(lambda x: x+2, numbers)
  • D map(lambda x: x/2, numbers)
Answer: Option A
Explanation: map() applies transformation function to each element
Q18
What will this code return: list(filter(lambda x: len(x) > 3, ['cat', 'dog', 'elephant']))?
  • A ['cat', 'dog', 'elephant']
  • B ['elephant']
  • C ['cat', 'dog']
  • D []
Answer: Option B
Explanation: filter() keeps elements where condition is True
Q19
Which operator is used in lambda for exponentiation?
  • A ^
  • B **
  • C ^^
  • D pow()
Answer: Option B
Explanation: ** is the exponentiation operator in Python
Q20
What is the result of: max([(1, 2), (3, 1), (2, 4)], key=lambda x: x[0])?
  • A (1, 2)
  • B (3, 1)
  • C (2, 4)
  • D Error
Answer: Option B
Explanation: max() with key function finds maximum based on specified element
Questions and Answers for Competitive Exams Various Entrance Test