ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print(len(' a b '.split()), len(' a b '.split(' ')), len('a\nb\n'.splitlines()), len('a\nb\n'.split('\n')))
  1. A. 2 4 2 3
  2. B. 2 3 2 3
  3. C. 2 4 3 3
  4. D. 2 4 2 4

Correct answer: A. 2 4 2 3

split() ignores all whitespace runs, while split(' ') keeps empty strings at both ends. splitlines does not create an empty last item, but split('\n') does.

More Python Programming questions

Exams that ask this topic