LearnFrenzy
Sign in Take a free test

Lambda Functions · Predict the Output · Question 8

A conditional lambda Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 8 Back to Exercise

What is the output of the following Python program?

main.py
grade = lambda m: "pass" if m >= 40 else "fail"
print(grade(40), grade(39), list(map(grade, [90, 12])))
  • A fail fail ['pass', 'fail']
  • B pass pass ['pass', 'pass']
  • C SyntaxError
  • D pass fail ['pass', 'fail'] Correct
Correct Answer: Option D

40 >= 40 is True. The lambda can be passed to map like any function.

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