A Question About split() Difference


Hi all.

I wonder something;

if we use this;
print(“some string”.split()) it outputs the splitted string like in a list [“some”, “string”]

if we use this;
print(“some string”.split(" ")) it does the same.

but if we delete the space between quotes like here;
print(“some string”.split("")) then its giving out an error like ValueError: empty separator

why is it happening? whats the important part of those quotes in there and why is split still working without them? whats the difference in here?

thank you.


Hi @terapro72461,

The default separator is whitespace, which could be a space character, a tab, or a run of such characters. You can supply another separator, which needs to be a string, but an empty string cannot work as a separator.

See Python: str.split for documentation.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.