ProgrammingModerateTCS NQT · Infosys

What is printed?

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

Correct answer: B. 2 3 3 1 -1

find returns the first index of 'l' (2), index with start 3 finds the next one at 3, and rfind returns the last at 3. find returns -1 when nothing matches, while index would raise ValueError.

More Python Programming questions

Exams that ask this topic