Does anyone have a clear way to explain the rule regarding str.split(sep=None)? The Docstring provides some explanation but not enough to understand the following behaviors
>>> s = '\n Hello\t World\nOpps\t '
>>> print(s.split()) #by default sep = None
['Hello', 'World', 'Opps']
>>> print(s.split(maxsplit = 1))
['Hello', 'World\nOpps\t ']
- The first print seems reasonable since it splits whenever whitespace appears, and then dump all the empty strings.
- The second one is a bit harder to understanding: if it only splits once, then it should condiser the 1st '\n' as the delimiter and results in an empty string
''(which should be dumped next) and' Hello World\nOpps\t'.
Thank you in advance for any consistent and logical explanation you may provide.
PS: I have included the Docstring in below, and I am aware of this question, and an answer there offers some help but a clear rule with official source is still missing. Without official source explanation, a rule is just something for users to memorize without understanding.
sep
The delimiter according which to split the string. None (the default value) means split according to any whitespace, and discard empty strings from the result.