ProgrammingHardTCS NQT · Wipro pattern

What is printed?

What is printed?
print('%s' % (1,), '%s' % ((1,),), '%r' % ((1, 2),))
  1. A. 1 (1,) (1, 2)
  2. B. (1,) (2,) (1, 2)
  3. C. 1 1 (3, 2)
  4. 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

Exams that ask this topic