ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

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

Correct answer: D. 2 3 1 1

index('c') finds the first c at 2, and rindex('a') finds the last a at 3. 'bca' starts at index 1, and the count of 'bc' in s[1:4] = 'bca' is 1.

More Python Programming questions

Exams that ask this topic