ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
print('%s' % (1,), '%s' % ((1,),), '%r' % ((1, 2),))- A. 1 (1,) (1, 2)
- B. (1,) (2,) (1, 2)
- C. 1 1 (3, 2)
- D. 1 (1,) 1, 9
Correct answer: A. 1 (1,) (1, 2)
A one-element tuple given to %s is unpacked, so (1,) gives 1. Wrapping it in another tuple passes the tuple itself, which prints as (1,). %r on a two-element tuple shows its repr.
More Python Programming questions
- What is printed? python print(1 if True else 0 or 2, not 0 or 3, (not 0) or 3, 0 or '' or None)
- 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]))