ProgrammingModerateAccenture · Capgemini pattern

What is printed?

What is printed?
print(" ".join(i * ch for i, ch in enumerate("xyz", 1)), list(enumerate("ab"))[-1])
  1. A. x yy zzz ('b', 1)
  2. B. xyz xyz xyz (1, 'b')
  3. C. x yy zzz (1, 'b')
  4. D. xx yyy zzzz (2, 'b')

Correct answer: C. x yy zzz (1, 'b')

enumerate("xyz", 1) starts counting at 1, giving (1, 'x'), (2, 'y'), (3, 'z'); int * str repeats the string, so the words are x, yy, zzz. Without a start argument counting begins at 0, and each item is an (index, value) tuple, so the last item of enumerate("ab") is (1, 'b'), not ('b', 1).

More Python Programming questions

Exams that ask this topic