ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print('ab'.startswith(('x', 'a')), 'abc'.endswith('', 3), 'abc'.index('c', -1), 'aXbX'.split('X', 1))
  1. A. True False 2 ['a', 'bX']
  2. B. True True 2 ['a', 'b', '']
  3. C. True True 2 ['a', 'bX']
  4. D. False True 2 ['a', 'bX']

Correct answer: C. True True 2 ['a', 'bX']

startswith accepts a tuple of prefixes. An empty suffix always matches, and the start index 3 is the end of the string, so the test is True. split with maxsplit 1 stops after the first separator.

More Python Programming questions

Exams that ask this topic