ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(1 if True else 0 or 2, not 0 or 3, (not 0) or 3, 0 or '' or None)
- A. 1 3 3 None
- B. 1 True 3 None
- C. 1 True 0 None
- D. 1 True True None
Correct answer: D. 1 True True None
The conditional expression binds loosest, so 1 if True else (0 or 2) is 1. not 0 is True, and or returns the first truthy value, while 0 or '' or None returns the last falsy value, None.
More Python Programming questions
- What is printed? python print(max(map(str, [9, 10, 2])), max([9, 10, 2]), min(map(int, ['10', '9'])))
- What is printed? python x = 0.1 3 y = 0.3 print(x == y, abs(x - y) < 1e-15, round(x, 15) == round(y, 15), x - y)
- What is printed? python print('ß'.isupper(), 'Dž'.istitle(), 'Dž'.isupper(), '1A'.isupper())
- What is printed? python print(f'{270:,}'[:8], len(f'{270:,}'), str(270)[-3:], ('%d' % 270)[-3:])
- What is printed? python data = [('x', 3), ('y', 1), ('z', 3)] print(max(data, key=lambda t: t[1]), min(data, key=lambda t: -t[1]))
- What is printed? python print(0.1 + 0.2 == 0.30000000000000004, 0.1 + 0.2 - 0.30000000000000004 == 0, '%.20f' % (0.1 + 0.2))