LearnFrenzy
Sign in Take a free test

Lambda Functions · Exercise 2 of 4

Lambda Functions Predict the Output

  • 15 questions
  • Page 2 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Read each Python program and choose what it prints. Every program was run on Python 3, so the answers are the real output.

Question 11 Medium

What is the output of the following Python program?

main.py
f = lambda: None
g = lambda *args: len(args)
print(f.__name__, f(), g(), g(1, 2, 3))
A f None 0 3
B <lambda> None 0 3
C <lambda> None 1 3
D <lambda> 0 3
Question page & discussion
Question 12 Easy

What is the output of the following Python program?

main.py
people = [{"n": "Asha", "age": 30}, {"n": "Ravi", "age": 25}, {"n": "Meera", "age": 28}]
print([p["n"] for p in sorted(people, key=lambda p: p["age"])])
print(max(people, key=lambda p: len(p["n"]))["n"])
A ['Asha', 'Meera', 'Ravi'] Meera
B ['Ravi', 'Meera', 'Asha'] Asha
C ['Ravi', 'Meera', 'Asha'] Meera
D ['Asha', 'Ravi', 'Meera'] Ravi
Question page & discussion
Question 13 Medium

What is the output of the following Python program?

main.py
from functools import partial

pow2 = partial(pow, 2)
binary = partial(int, base=2)
print(pow2(10), binary("1011"), binary("1011", base=8))
A 1024 11 521
B 100 11 521
C 1024 1011 11
D 1024 11 11
Question page & discussion
Question 14 Medium

What is the output of the following Python program?

main.py
x = 10
f = lambda: x
g = lambda x=x: x
x = 20
print(f(), g())
A 10 10
B 20 20
C 20 10
D 10 20
Question page & discussion
Question 15 Hard

What is the output of the following Python program?

main.py
add = lambda a: lambda b: a + b
compose = lambda f, g: lambda x: f(g(x))
inc_then_double = compose(lambda x: x * 2, add(1))
print(add(2)(3), list(map(add(10), [1, 2])), inc_then_double(5))
A 5 [11, 12] 11
B 6 [11, 12] 12
C 5 [11, 12] 12
D TypeError
Question page & discussion
Up next · Exercise 3Find the Error10 questions

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links