ProgrammingHardTCS NQT · Infosys

What is printed?

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

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

A negative maxsplit means no limit, so 'a,b' splits fully. A maxsplit of 0 makes no splits at all, and split with maxsplit 1 on whitespace stops after the first field.

More Python Programming questions

Exams that ask this topic