ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(f'{"x"!r}', '%s and %r' % ('x', 'x'), '{!s} {!r}'.format('x', 'x'))
  1. A. x 'x' and x x y
  2. B. 'x' x and 'x' 'x' 'x' 'x'
  3. C. 'x' x and 'x' x 'x'
  4. D. 'x' x and x y 'x'

Correct answer: C. 'x' x and 'x' x 'x'

An f-string field with !r applies repr, so the quoted x comes first. %s prints x plainly while %r shows quotes, and str.format's !s prints x while !r shows 'x'.

More Python Programming questions

Exams that ask this topic