str.split() Split by separator
Last updated: 2026-09-22
str.split() Split by separator
str.split(sep=None, maxsplit=-1) splits the string on sep and returns a list.
| Category | String Methods |
|---|---|
| Kind | Built-in Type Method |
| Python Version | all |
📝 Syntax
str.split(sep=None, maxsplit=-1)
⚙️ Parameters
| sep Optional | Separator; None means split on any run of whitespace.(Default:None) |
|---|---|
| maxsplit Optional | Maximum number of splits; -1 means no limit.(Default:-1) |
Returns:list[str]. The substrings produced by splitting on sep.
Mutates the original:No (returns a new object)
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
['a', 'b', 'c']
['a', 'b', 'c']
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QHow does it split when no argument is passed?
AWith sep=None it splits on any run of whitespace, merging multiple spaces and newlines: 'a b \n c'.split() gives ['a', 'b', 'c'].
QHow does the behavior differ when a separator is specified?
AConsecutive separators are not merged: 'a,,b'.split(',') gives ['a', '', 'b']; and trailing empty strings are dropped: 'a,b,'.split(',') gives ['a', 'b'].
QWhat does split() return? Does it modify the original string?
AIt returns a list[str] list, and the original string is unchanged.
QHow do I split only the first few segments?
AUse the maxsplit parameter: 'a,b,c,d'.split(',', 2) gives ['a', 'b', 'c,d'].