ProgrammingHardIBM · Deloitte pattern

What is printed?

What is printed?
s = "Mississippi"
print(s.count("ss"), s.count("i"))
  1. A. 4 4
  2. B. 2 4
  3. C. 2 2
  4. D. 4 2

Correct answer: B. 2 4

str.count finds NON-overlapping matches: 'ss' appears at positions 2-3 and 5-6, giving 2. The letter 'i' appears at positions 1, 4, 7, 10, giving 4.

More Python Programming questions

Exams that ask this topic