ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
s = 'mississippi'
print(s.count('ss'), s.count('issi'), s.index('s', 3), s.rindex('i', 0, 5))
  1. A. 2 1 2 4
  2. B. 2 1 3 1
  3. C. 2 1 3 4
  4. D. 2 2 3 4

Correct answer: C. 2 1 3 4

'ss' occurs twice without overlap. 'issi' occurs at positions 1 and 4, which overlap, and count skips overlapping matches, so it reports 1. index('s', 3) is 3, and rindex('i', 0, 5) finds the last i before position 5, at index 4.

More Python Programming questions

Exams that ask this topic