Strings · Class 11 · CBSE · Science Computer Science

What is the output of the following Python code? s = "Mississippi"; print(s.count("s"), s.find("sip"))

Practice question from Strings (Class 11 · CBSE · Science Computer Science), with the correct answer and a step-by-step solution.

easy · MCQ · Q-1AA662

What is the output of the following Python code? s = "Mississippi"; print(s.count("s"), s.find("sip"))

  1. A.4 5Correct answer
  2. B.4 4
  3. C.3 5
  4. D.3 4

Solution

count("s") returns 4 because the character s occurs four times. The substring "sip" first begins at index 5, so find("sip") returns 5.

More from Strings

All of Strings

Practise more Computer Science

Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.

Start practising free

Free to start · No credit card needed