ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
s = 'ab' * 2 + 'c'
print(s.endswith('bc'), s.startswith('ab', 2), s.find('ab', 1), s.count('ab'))
  1. A. True False 2 2
  2. B. True True 2 2
  3. C. True True 0 2
  4. D. False True 2 2

Correct answer: B. True True 2 2

The string is 'ababc', so it ends with 'bc', and from index 2 it still starts with 'ab'. find from index 1 locates the second 'ab' at index 2, and count gives 2.

More Python Programming questions

Exams that ask this topic