ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
s = 'abcabc'
print(s.find('c'), s.find('c', 3), s.rfind('c', 0, 4), s.count('c', 2))
  1. A. 2 2 2 2
  2. B. 2 5 5 2
  3. C. 2 5 2 1
  4. D. 2 5 2 2

Correct answer: D. 2 5 2 2

find returns the first c at index 2. With start 3 it finds the c at 5. rfind searches indices 0 to 3 and returns the c at 2. count from index 2 includes both c's.

More Python Programming questions

Exams that ask this topic