String Methods

str.split()

Split into a list of fields, selecting up to maxsplit separator occurrences from the left. Explicit nonempty sep preserves empty fields between consecutive separators and at the edges. None groups consecutive whitespace and omits edge empty fields; empty or whitespace-only input produces an empty list in that mode. With maxsplit=0 and sep=None only the corresponding outer whitespace run is removed. A negative maxsplit is unlimited. The original string is unchanged.

Formal Syntax & Structure

python syntaxpython
text.split(sep=None, maxsplit=-1)

Parameters & Attributes

NameTypeDescription
sepstr | NoneLiteral nonempty separator, or None for whitespace mode.
maxsplitintMaximum number of splits; negative means unlimited.

Return Value

list[str]

Fields in original left-to-right order.

Working Example

Example Snippetpython
print("a:b:c".split(":", 1))print(" a   b ".split())print("a,,b,".split(","))
Python Reference