LearnFrenzy
Sign in Take a free test

Lambda Functions · Lambda Functions MCQ · Question 9

if-else in a lambda Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 9 Back to Exercise

Which lambda is valid?

  • A lambda n: if n % 2 == 0: "even"
  • B lambda n: "even" if n % 2 == 0
  • C lambda n: "even" if n % 2 == 0 else "odd" Correct
  • D lambda n: return "even"
Correct Answer: Option C

A conditional expression needs both if and else parts; an if statement is not allowed.

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