ProgrammingHardInfosys · Accenture · Capgemini pattern

What is printed on the third line?

What is printed on the third line?
print('a,b,,c'.split(','))
print('  a  b '.split())
print(' a b '.split(' '))
  1. A. ['a', 'b', 'c']
  2. B. ['', 'a', 'x', '']
  3. C. ['a', 'b', 'c', 'd']
  4. D. ['', 'a', 'b', '']

Correct answer: D. ['', 'a', 'b', '']

split() with no argument collapses runs of whitespace and drops empty strings at the ends. split(' ') keeps an empty string for every separator it finds, including the leading and trailing ones.

More Python Programming questions

Exams that ask this topic