Lambda Functions Questions and Answers

Take Exam

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
Show Answer Report

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
Show Answer Report

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)
Show Answer Report

14. What does this lambda do: lambda s: s[::-1]?

  • Converts to uppercase
  • Reverses the string
  • Removes whitespace
  • Splits the string
Show Answer Report

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)
Show Answer Report

16. What is the output of: (lambda x: x if x > 0 else -x)(-5)?

  • -5
  • 5
  • 0
  • Error
Show Answer Report

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)
Show Answer Report

18. What will this code return: list(filter(lambda x: len(x) > 3, ['cat', 'dog', 'elephant']))?

  • ['cat', 'dog', 'elephant']
  • ['elephant']
  • ['cat', 'dog']
  • []
Show Answer Report

19. Which operator is used in lambda for exponentiation?

  • ^
  • **
  • ^^
  • pow()
Show Answer Report

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
Show Answer Report
Questions and Answers for Competitive Exams Various Entrance Test