ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
s = 'a b  c'
print(s.split(' '), s.split(), len(s.split(' ')) - len(s.split()))
  1. A. ['a', 'b', '', 'c'] ['a', 'b', 'c'] 1
  2. B. ['a', 'b', 'c'] ['a', 'b', 'c'] 0
  3. C. ['a', 'b', '', 'c'] ['a', 'b', 'c'] 2
  4. D. ['a', 'b', 'c'] ['a', 'b'] 1

Correct answer: A. ['a', 'b', '', 'c'] ['a', 'b', 'c'] 1

split(' ') keeps the empty field between the two spaces, so it has four pieces. split() with no argument removes every empty field and returns three words, which gives a difference of 1.

More Python Programming questions

Exams that ask this topic