ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
print('%s|%r' % ("it's", "it's"))
  1. A. it's|"its"
  2. B. it's|"is"
  3. C. it's|"it's"
  4. D. its|"it's"

Correct answer: C. it's|"it's"

%s uses str() and shows the text as-is, while %r uses repr(), which wraps a string that contains a single quote in double quotes. That is why the second part shows the quotes.

More Python Programming questions

Exams that ask this topic