CKTIS / Python
str.split
Splits text into fields using whitespace or an explicit separator.
Version: Python 3.14; repository image, production runtime not attested
Syntax
s.split(sep=None, maxsplit=-1)Splits text into fields using whitespace or an explicit separator.
Whitespace mode collapses runs, while explicit separators preserve empty fields between adjacent delimiters.
With sep=None and unlimited splitting, leading and trailing whitespace disappear and interior whitespace runs act as one delimiter. With an explicit comma, a,,b contains an empty middle field. The default maxsplit=-1 imposes no limit. Once a finite limit is reached, the remainder retains its trailing whitespace.
assert " a b ".split(None, 1) == ["a", "b "]
assert " a b ".split(None, 0) == ["a b "]
Examples
print(" a b ".split())
print("a,,b".split(","))
Result
['a', 'b'] ['a', '', 'b']
With sep=None and unlimited splitting, leading and trailing whitespace disappear and interior whitespace runs act as one delimiter. With an explicit comma, a,,b contains an empty middle field. The default maxsplit=-1 imposes no limit. Once a finite limit is reached, the remainder retains its trailing whitespace.