ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(repr("it's"), repr('say "hi"'), len('\x41\101'), len(r'\n'))
  1. A. "it's" 'say "hi"' 2 1
  2. B. "it's" 'say "hi"' 3 2
  3. C. "it's" 'say "hi"' 2 2
  4. D. "it's" 'say "hi"' 4 2

Correct answer: C. "it's" 'say "hi"' 2 2

repr() uses double quotes when a string contains a single quote and no double quote, and single quotes otherwise. '\x41\101' is two characters (A and A), while the raw string r'\n' keeps the backslash and n, so it is two characters too.

More Python Programming questions

Exams that ask this topic