ProgrammingModerateGATE CS · Product-company placement

What is printed?

What is printed?
s = "Mississippi"
print(s.count("ss"), s.count("issi"), s.replace("ss", "S"), s.lower().index("s", 4))
  1. A. 2 1 MiSiSippi 5
  2. B. 2 2 MiSiSippi 5
  3. C. 2 1 MiSSippi 5
  4. D. 2 1 MiSiSippi 6

Correct answer: A. 2 1 MiSiSippi 5

count and replace scan left to right for non-overlapping matches: 'ss' occurs twice, while 'issi' occurs at 1 and again overlapping at 4, so only one is counted. index('s', 4) starts at index 4 ('i') and finds 's' at 5.

More Python Programming questions

Exams that ask this topic