str.split()

Break the string into a list of substrings on a delimiter — or on any whitespace when no delimiter is given.

String methodPython 2.0+Live demo
Common call
"a,b,c".split(",")
Returns
list of str — original unchanged
Replaces
sep=None splits on whitespace runs and drops empties
Watch out
"a,,b".split(",") keeps the empty piece; split() does not
str.split(sepsepThe delimiter. None (the default) means split on runs of whitespace and drop empty strings. An empty string raises ValueError.type: str | None · default: None=None, maxsplitmaxsplitMaximum number of splits. Negative or omitted means no limit; the last list item holds the remainder.type: int · default: -1=-1)
list[str]

Demo

Live evaluation
Try:
Inputs
stringstrthe source
sepstrempty = whitespace
maxsplitint-1 = no limit
Output
'a,b,c'.split(',')
['a', 'b', 'c']

str.split() returns a new list of substrings. With an explicit sep, adjacent separators produce empty strings. With sep omitted (leave the field empty here), runs of whitespace act as one separator and empty strings are dropped.

Parameters

NameTypeRequiredDescription
sepstr | Noneno (None)The delimiter. None (the default) means split on runs of whitespace and drop empty strings. An empty string raises ValueError.
maxsplitintno (-1)Maximum number of splits. Negative or omitted means no limit; the last list item holds the remainder.

Return value

list[str]A new list of the substrings between separators. The original string is unchanged.

Common patterns

Words from a sentence
The no-argument form handles any amount of whitespace, including tabs and newlines.
words = "the  quick\tbrown fox".split()
# ['the', 'quick', 'brown', 'fox']
Key-value pair with maxsplit
Limit splitting so values containing the delimiter survive intact.
key, value = "PATH=/usr/bin:/bin".split("=", 1)
# key='PATH', value='/usr/bin:/bin'
CSV line (simple cases)
Fine for trusted simple data — reach for the csv module when fields can be quoted.
fields = line.split(",")

Examples

1. Split on a delimiter
"a,b,c".split(",")
Returns
['a', 'b', 'c']
2. Split on whitespace (default)
" one two ".split()
Returns
['one', 'two']
3. Limit the number of splits
"a,b,c".split(",", 1)
Returns
['a', 'b,c']
4. Delimiter not present
"abc".split("-")
Returns
['abc']

Pitfalls

1. split(",") and split() treat empties differently
An explicit separator keeps empty pieces between adjacent delimiters; the whitespace form drops them.
Surprising
"a,,b".split(",")
['a', '', 'b']
Filter if unwanted
[p for p in s.split(",") if p]
['a', 'b']
2. Empty separator raises
Unlike str.replace, split does not accept an empty sep. Use list(s) to get characters.
Raises
"abc".split("")
ValueError: empty separator
Fix
list("abc")
['a', 'b', 'c']
3. Unpacking can fail on unexpected input
Tuple-unpacking the result assumes an exact piece count. Cap it with maxsplit.
Fragile
key, value = "a=b=c".split("=")
ValueError: too many values to unpack
Fix
key, value = "a=b=c".split("=", 1)
('a', 'b=c')

When to use

Use it
  • Tokenizing on a literal delimiter
  • Whitespace word-splitting — the no-arg form is built for it
  • Peeling one prefix off with maxsplit=1
Reach for something else
  • Pattern-based splitting → re.split
  • Quoted CSV data → csv module
  • Only need the two ends → str.partition
  • Splitting into characters → list(s)

Notes

Complexity
O(n) — single pass over the source
Return
new list[str] — source untouched
CPython impl
Objects/unicodeobject.c :: unicode_split
Memory
Allocates the list plus one new str per piece
Thread-safe
Yes — str is immutable

FAQ

split() treats any run of whitespace as one separator and drops empty results; split(" ") splits on every single space, producing empty strings for doubled spaces.

"a  b".split()      # ['a', 'b']
"a  b".split(" ")   # ['a', '', 'b']

History

2.0
Method available on the unified string type.