LearnFrenzy
Sign in Take a free test

Lambda Functions · Predict the Output · Question 14

A lambda reads a variable at call time Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 14 Back to Exercise

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 Correct
  • D 10 20
Correct Answer: Option C

f looks up x when called (20). g's default was evaluated when g was created (10).

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links