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))
- A. 5 9 6
- B. 5 9 5
- C. 5 8 6
- 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
- What is printed? python print(sorted([2.0, 2, True, 1.5]))
- What is printed? python print(len({1: 'a', True: 'b', 1.0: 'c'}), list({True: 1, 1: 2}.keys()))
- What is printed? python print(int(1e308) > 10308, float('1e-400'), 5e-324 / 2, 5e-324 / 2 == 0)
- What is printed? python print(1e-7 == 0.0000001, 1e-7, 0.0000001, 1.0e5 == 100000.0, 123e-2)
- What is printed? python print(7 // 2 2 + 7 % 2 == 7, -(7 // 2) 2 + -(7 % 2) == -7, (-7) // 2 2 + (-7) % 2)
- What is printed? python print(int('12' '34') + 1, '%d' % 3.9, '%i' % -3.9, '%+d' % 0)