ProgrammingHardAccenture pattern

What is printed?

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

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

Splitting on the literal '-' with no limit keeps every field between delimiters, including the EMPTY string between the two consecutive dashes, giving ['a','b','','c']. Limiting to 1 split stops after the first dash, giving ['a', 'b--c'].

More Python Programming questions

Exams that ask this topic