ProgrammingModerateTCS NQT · Wipro pattern

What is printed?

What is printed?
print('abc'.index('c'), 'abcabc'.rfind('b'), 'abc'.find('d'), len('abc'[1:]))
  1. A. 2 4 0 2
  2. B. 2 5 -1 2
  3. C. 2 4 -1 2
  4. D. 3 4 -1 2

Correct answer: C. 2 4 -1 2

index finds the first c at position 2, and rfind returns the last b at position 4. find returns -1 when the substring is missing, and slicing from position 1 leaves two characters.

More Python Programming questions

Exams that ask this topic