ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print('%s' % 'x' * 3, '%s' * 2 % ('a', 'b'), '%s' % ('x' * 3))
  1. A. xxx ab xx
  2. B. xx ab xxx
  3. C. xxx ab xxx
  4. D. xxx ba xxx

Correct answer: C. xxx ab xxx

'%s' % 'x' is x and multiplying by 3 gives xxx. '%s' * 2 builds the format string %s%s before applying % to the pair, and the last one formats the three-x string directly.

More Python Programming questions

Exams that ask this topic