ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(('a' 'b' 'c').upper(), 'x' 'y' * 2, ('%d' % 3) * 2)
  1. A. ABC xyy 33
  2. B. ABC xyxy 3
  3. C. ABCABC xyxy 33
  4. D. ABC xyxy 33

Correct answer: D. ABC xyxy 33

Adjacent string literals join at compile time, so 'a' 'b' 'c' is 'abc' and the upper() call applies to it. The * operator then applies to the joined 'xy' literal, giving xyxy.

More Python Programming questions

Exams that ask this topic