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']

1 comment:

perlknowledge said...

What is the output?

f = lambda x: x \* 2 print(f(5))

The lambda multiplies its argument by 2, so f(5) produces 10.

What is the output?

add = lambda a, b: a + b print(add(3, 7))

The lambda adds its two arguments, so 3 + 7 equals 10.

What is the output?

square = lambda x: x 2 print(square(4))

The expression 4 \*\* 2 evaluates to 16.

What is the output?

nums = \[1, 2, 3, 4\] result = list(map(lambda x: x \* 2, nums)) print(result)

Each element is multiplied by 2, producing this list.

What is the output?

nums = \[1, 2, 3, 4, 5\] result = list(filter(lambda x: x % 2 == 0, nums)) print(result)

The condition x % 2 == 0 is true for the even values 2 and 4.

What is the output?

nums = \[3, 1, 2\] result = sorted(nums, key=lambda x: x) print(result)

The key returns each number itself, so sorted() orders the values in ascending order.

What is the output?

f = lambda x: x + 10 print(f(2) \* 3)

The lambda first produces 12 from 2 + 10, and 12 × 3 equals 36.

What is the output?

multiply = lambda a, b: a \* b print(multiply(4, 5))

The lambda multiplies 4 by 5, giving 20.

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

A lambda returns the value produced by its expression when it is called.

What is the output?

words = \["cat", "elephant", "dog"\] result = sorted(words, key=lambda x: len(x)) print(result)

The key returns each word's length, so the words are ordered from shortest to longest: 3, 3, 8.