ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
x = 5
y = x if x > 3 else 0 + 1 if x else -1
print(y, (lambda a, b=2: a ** b)(3), (lambda *a: sum(a))(1, 2, 3))
  1. A. 5 9 6
  2. B. 5 9 5
  3. C. 5 8 6
  4. D. 3 9 6

Correct answer: A. 5 9 6

The conditional expression chains to the right, and x > 3 gives 5. The lambda's default b=2 makes it 3 ** 2 = 9, and the variadic sum is 6.

More Python Programming questions

Exams that ask this topic