ProgrammingModerateTCS NQT · Wipro pattern

What is printed?

What is printed?
print(len('ab' + 'c' * 0), 'ab'[1:][0] * 2, ('ab' * 2)[::3])
  1. A. 2 aa ab
  2. B. 2 bb a
  3. C. 2 bb ab
  4. D. 3 bb ab

Correct answer: C. 2 bb ab

'c' * 0 adds nothing, so the length is 2. 'ab'[1:] is b, which repeated gives bb. In abab, stepping by three takes indices 0 and 3, giving ab.

More Python Programming questions

Exams that ask this topic