ProgrammingHardTCS CodeVita · Infosys HackWithInfy · Product Company SDE

What does the following Python 3 code print? s = "committee" print(s.count("m"), s.find("m"), s.rfind("m"), s.index("m", s.find("m") + 1) if s.count("m") > 1 else -1)

  1. A. 2 2 3 3
  2. B. 2 3 2 -1
  3. C. 2 2 3 2
  4. D. 7 2 3 -1

Correct answer: A. 2 2 3 3

count tallies non-overlapping matches, find/rfind give first/last index, and index(sub, start) searches from start. Output: 2 2 3 3.

More Python Programming questions

Exams that ask this topic