Question 4
Back to Exercise
What is the output of the following Python program?
print("a,b,,c".split(","), " a b ".split(), "-".join(["x", "y", "z"]))
- A ['a', 'b', '', 'c'] ['a', 'b'] x-y-z Correct
- B ['a', 'b', 'c'] ['a', 'b'] x-y-z
- C ['a', 'b', '', 'c'] ['', 'a', '', 'b', ''] x-y-z
- D ['a', 'b', '', 'c'] ['a', 'b'] -x-y-z-
Correct Answer: Option A
With an explicit separator, two commas in a row give an empty string. split() with no argument collapses whitespace. join puts the separator only between items.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!