ProgrammingModerateWipro NLTH · Python

What is printed?

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

Correct answer: B. ['a', 'b', '', 'c'] ['a', 'b,,c'] ['x', 'y']

split(',') keeps the empty field; maxsplit=1 splits only at the first comma; split() with no argument discards runs of whitespace.

More Python Programming questions

Exams that ask this topic