ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
s = 'one two  three'
print(s.split(' '), len(s.split()), s.split(None, 1)[1], '-'.join(s.split()))
  1. A. ['one', 'two', '', 'three'] 3 two three one-two-three
  2. B. ['one', 'two', 'four'] 3 two three one-two-three
  3. C. ['one', 'two', '', 'three'] 2 two three one-two-three
  4. D. ['one', 'two', '', 'three'] 3 two three one-two-threes

Correct answer: A. ['one', 'two', '', 'three'] 3 two three one-two-three

split(' ') keeps an empty string for the double space, while split() with no argument collapses runs of spaces. split(None, 1) stops after the first word and keeps the rest unchanged.

More Python Programming questions

Exams that ask this topic