ProgrammingModerateTCS NQT · Wipro pattern

What is printed?

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

Correct answer: D. 2 3 -1 2

index and rindex find the first and last l, at positions 2 and 3. find returns -1 when the text is missing, while index would raise ValueError. count gives the number of l characters.

More Python Programming questions

Exams that ask this topic