Lambda Functions Questions and Answers

Practice Mode
Showing 10 of 25 questions
Q21
How do you check if a number is odd using lambda?
  • A lambda x: x % 2 == 0
  • B lambda x: x % 2 == 1
  • C lambda x: x / 2 == 1
  • D lambda x: x * 2 == 1
Answer: Option B
Explanation: Odd numbers have remainder 1 when divided by 2
Q22
What will be printed: f = lambda a, b: a if a > b else b; print(f(7, 3))?
  • A 7
  • B 3
  • C 10
  • D True
Answer: Option A
Explanation: Lambda returns the larger of two numbers
Q23
Which data type can lambda functions return?
  • A Only integers
  • B Only strings
  • C Only booleans
  • D Any data type
Answer: Option D
Explanation: Lambda functions can return any data type
Q24
What is the output of: list(map(lambda x: x*2, [1, 2, 3]))?
  • A [1, 2, 3]
  • B [2, 4, 6]
  • C [1, 4, 9]
  • D [2, 4, 8]
Answer: Option B
Explanation: map() applies the doubling operation to each element
Q25
How do you sort strings by their length using lambda?
  • A sorted(strings, key=lambda x: len(x))
  • B sorted(strings, key=lambda x: x.length)
  • C sorted(strings, lambda x: len(x))
  • D sorted(strings, key=len(x))
Answer: Option A
Explanation: sorted() with key function can sort based on string length
Questions and Answers for Competitive Exams Various Entrance Test