ProgrammingHardTCS NQT · Wipro pattern

What is printed?

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

Correct answer: A. -1 3

find only searches the slice from index 3 up to 5, which is ab, so it returns -1. rfind searches indices 0 to 3, and the last a in that range is at index 3.

More Python Programming questions

Exams that ask this topic