str.split()

Added in v3.9 · Updated March 13, 2026 · String Methods
stdlib string methods

The split() method breaks a string into a list of substrings. By default, it splits on whitespace, but you can specify a custom separator. This is one of the most frequently used string methods in Python.

Signature

str.split(sep=None, maxsplit=-1)

Parameters

ParameterTypeDefaultDescription
sepstrNoneThe delimiter to split on. If None, splits on any whitespace.
maxsplitint-1Maximum number of splits. -1 means no limit.

Return Value

Returns a list of strings. The substrings do not include the separator.

Basic Examples

# Split on whitespace (default)
text = "hello world python"
text.split()
# Result: ['hello', 'world', 'python']

# Split on a specific separator
text = "one,two,three"
text.split(",")
# Result: ['one', 'two', 'three']

# Split with maxsplit limit
text.split(",", 1)
# Result: ['one', 'two,three']

How It Works

When sep is None, consecutive whitespace characters are treated as a single separator:

# Multiple spaces become one separator
"hello   world".split()
# Result: ['hello', 'world']

# Tabs and spaces together
"hello\tworld".split()
# Result: ['hello', 'world']

# Leading and trailing whitespace is ignored
"   hello world   ".split()
# Result: ['hello', 'world']

When you provide a sep value, the string splits only on that exact substring:

# Split on double hyphen
"foo--bar--baz".split("--")
# Result: ['foo', 'bar', 'baz']

# Consecutive separators create empty strings
"a::b::".split("::")
# Result: ['a', 'b', '']

# Separator not found returns original string in list
"abc".split("-")
# Result: ['abc']

The maxsplit Parameter

The maxsplit argument limits how many splits occur:

# No limit (default)
"a,b,c,d".split(",")
# Result: ['a', 'b', 'c', 'd']

# Limit to 1 split
"a,b,c,d".split(",", 1)
# Result: ['a', 'b,c,d']

# Limit to 2 splits
"a,b,c,d".split(",", 2)
# Result: ['a', 'b', 'c,d']

# maxsplit=0 returns the string unchanged
"a,b,c".split(",", 0)
# Result: ['a,b,c']

Common Use Cases

Parsing CSV-like data

line = "name,email,phone"
fields = line.split(",")
# fields = ['name', 'email', 'phone']

Breaking a sentence into words

sentence = "The quick brown fox"
words = sentence.split()
# words = ['The', 'quick', 'brown', 'fox']

Splitting a filename from extension

filename = "document.pdf"
name, ext = filename.split(".")
# name = 'document', ext = 'pdf'

# For files with multiple dots
archive = "backup.2024.01.15.tar.gz"
parts = archive.split(".", 1)
# parts = ['backup', '2024.01.15.tar.gz']

Processing log lines

log_entry = "2024-01-15 ERROR Connection timeout"
parts = log_entry.split(" ", 1)
# parts = ['2024-01-15', 'ERROR Connection timeout']

Practical Notes

  • split() always returns a list, even if the string isn’t changed
  • The separator is not included in any of the resulting substrings
  • Empty strings appear in the result when separators are consecutive or at boundaries
  • For splitting on newlines specifically, .splitlines() is often more convenient

See Also