ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
print('%s and %r' % ('a', 'a'))
  1. A. 'a' or 'a'
  2. B. a and b
  3. C. s and 'a'
  4. D. a and 'a'

Correct answer: D. a and 'a'

%s uses str, which leaves a unquoted, while %r uses repr, which adds quotes around a.

More Python Programming questions

Exams that ask this topic