Showing posts with label lambda function. Show all posts
Showing posts with label lambda function. Show all posts

Thursday, September 17, 2026

Python Lambda Function Quiz

 Python Lambda Function Quiz


1. What is the output? f = lambda x: x * 2 print(f(5))

   A. 25

   B. 10

   C. 7

   D. 5


2. What is the output? add = lambda a, b: a + b print(add(3, 7))

   A. 10

   B. 4

   C. 37

   D. 21


3. What is the output? square = lambda x: x ** 2 print(square(4))

   A. 16

   B. 6

   C. 8

   D. 12


4. What is the output? nums = [1, 2, 3, 4] result = list(map(lambda x: x * 2, nums)) print(result)

   A. [2, 3, 4, 5]

   B. [1, 2, 3, 4]

   C. [2, 4, 6, 8]

   D. [1, 4, 9, 16]


5. What is the output? nums = [1, 2, 3, 4, 5] result = list(filter(lambda x: x % 2 == 0, nums)) print(result)

   A. [2, 4]

   B. [2, 3, 4]

   C. [1, 2, 3, 4]

   D. [1, 3, 5]


6. What is the output? nums = [3, 1, 2] result = sorted(nums, key=lambda x: x) print(result)

   A. [3, 2, 1]

   B. [2, 1, 3]

   C. [1, 2, 3]

   D. [3, 1, 2]


7. What is the output? f = lambda x: x + 10 print(f(2) * 3)

   A. 36

   B. 16

   C. 26

   D. 6


8. What is the output? multiply = lambda a, b: a * b print(multiply(4, 5))

   A. 9

   B. 45

   C. 1

   D. 20


9. What does a Python lambda expression return when its expression is evaluated?

   A. Always None

   B. Always a Boolean

   C. The evaluated expression result

   D. Always a string


10. What is the output? words = ["cat", "elephant", "dog"] result = sorted(words, key=lambda x: len(x)) print(result)

   A. ['cat', 'dog', 'elephant']

   B. ['cat', 'elephant', 'dog']

   C. ['dog', 'cat', 'elephant']

   D. ['elephant', 'cat', 'dog']