Practice mode Python

What is the output of the following Python code? print(“a,b,,c”.split(“,”))

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

Explanation

When a separator is given, split() treats consecutive separators as delimiting empty strings, so the two adjacent commas produce an empty string item. Only split() with no argument collapses runs of whitespace and discards empty items. This difference often matters when parsing CSV-like data with blank fields.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.