ProgrammingModerateTCS NQT · Wipro pattern

What is printed?

What is printed?
parts = []
for i in range(3):
    parts.append(str(i) * i)
print(repr(''.join(parts)), ''.join(map(str, range(3))))
  1. A. '122' 012
  2. B. '1220' 012
  3. C. '122' 210
  4. D. '022' 012

Correct answer: A. '122' 012

Multiplying a string by 0 gives the empty string, so the parts are '', '1' and '22'. They join to '122', and range(3) mapped to str and joined gives '012'.

More Python Programming questions

Exams that ask this topic