ProgrammingHardTCS NQT · Wipro pattern

What is printed?

What is printed?
s = 'aaaa'
print(s.count('aa'), s.replace('aa', 'b'), 'a,,b'.split(','), ' x  y '.split(' '))
  1. A. 2 bb ['a', 'bb'] ['x', 'y']
  2. B. 2 bb ['a', '', 'b'] ['x', 'yy']
  3. C. 2 bb ['a', '', 'b'] ['', 'x', '', 'y', '']
  4. D. 3 bb ['a', '', 'b'] ['', 'x', '', 'y', '']

Correct answer: C. 2 bb ['a', '', 'b'] ['', 'x', '', 'y', '']

count and replace scan left to right without overlap, so aaaa has two aa pairs. split with an explicit separator keeps the empty fields between separators.

More Python Programming questions

Exams that ask this topic