ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
a = 'ab'
b = a * 3
print(b.count('ab'), b.count('aba'), len(b.split('b')))
  1. A. 3 1 4
  2. B. 3 2 4
  3. C. 3 1 3
  4. D. 2 1 4

Correct answer: A. 3 1 4

'ababab' contains three non-overlapping 'ab' pairs and one 'aba' match. Splitting on 'b' gives four pieces, including the empty piece at the end.

More Python Programming questions

Exams that ask this topic