ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print('%s' % [1, 'a'], '%r' % 'a', '%5.2s|' % 'hello', '%c' % 65)
  1. A. [1, 'a'] 'a' he| A
  2. B. [1, 'a'] 'a' he| 65
  3. C. [1, 'a'] 'a' hel| A
  4. D. [1, 'a'] 'a' he| B

Correct answer: A. [1, 'a'] 'a' he| A

%s uses str() of the list, and %r uses repr() of the string. %5.2s keeps two characters and pads them to width five, and %c turns the integer 65 into the character A.

More Python Programming questions

Exams that ask this topic