ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
s = 'hello'
print(s.index('l'), s.rfind('l'), s.find('l', 3), s.index('lo'))
  1. A. 2 3 -1 3
  2. B. 2 2 3 3
  3. C. 3 3 3 3
  4. D. 2 3 3 3

Correct answer: D. 2 3 3 3

index and find return the first match from the left, which is 2. rfind gives the last l at 3. find from index 3 still finds the l at 3. 'lo' starts at index 3.

More Python Programming questions

Exams that ask this topic