The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Use list(text) to turn a string into its sequence elements, text.split(delimiter) to divide it at an exact delimiter, and text.split() to split on runs of whitespace. If separators are alternative patterns, use re.split(). The right choice depends on whether you want individual string elements or fields separated by text.
How do you split a string into characters?
Pass the string to list():
text = "Python"
characters = list(text)
print(characters) # ['P', 'y', 't', 'h', 'o', 'n']
Python strings are sequences, so list(text) returns their sequence elements as individual strings. This is not always the same as splitting into user-perceived characters: a visible character can be made from multiple Unicode code points, and list() does not combine those into grapheme clusters.
As an Amazon Associate I earn from qualifying purchases.
How do you split at a delimiter?
Pass the exact delimiter string to str.split(). Python splits at each occurrence and excludes the delimiter from the returned fields.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →text = "red,green,blue"
fields = text.split(",")
print(fields) # ['red', 'green', 'blue']
The delimiter can contain more than one character; Python treats the whole string as one separator. For example, "1<>2<>3".split("<>") returns ['1', '2', '3']. The Python 3.14.8 documentation describes this behavior in its built-in types reference.
#1 Best Overall
Repeated delimiters and empty fields
With an explicit delimiter, consecutive occurrences are not collapsed. Empty fields between them are preserved:
"1,,2".split(",") # ['1', '', '2']
Splitting an empty string with an explicit delimiter returns a one-item list containing an empty string:
Rank #2
"".split(",") # ['']
How do you split on whitespace?
Call split() without an argument to treat runs of whitespace as a single separator. Leading and trailing whitespace do not create empty fields.
Free tools Windows power users keep installed
One-click scans. No signup required.
text = "red greentblue"
words = text.split()
print(words) # ['red', 'green', 'blue']
Empty and whitespace-only strings produce an empty list when split this way:
"".split() # []
" t".split() # []
How can you control which splits happen?
Limit splits from the left
Set maxsplit to limit how many times split() divides the string. The result can contain at most maxsplit + 1 elements.
"one,two,three".split(",", maxsplit=1)
# ['one', 'two,three']
Limit splits from the right
Use rsplit() when the limited splits should start at the right end:
"one,two,three".rsplit(",", maxsplit=1)
# ['one,two', 'three']
Split once and keep the delimiter
Use partition(sep) when you want to divide at the first occurrence and retain the separator in the result. It returns a three-item tuple: the text before the match, the separator, and the text after it.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minute"name=value=extra".partition("=")
# ('name', '=', 'value=extra')
What if there are several possible delimiters?
str.split() accepts one exact separator string, not a set of alternative separators. Use re.split() from Python’s regular-expression module when the separators are patterns or alternatives.
Best Value
import re
text = "red,green;blue"
fields = re.split(r"[,;]", text)
print(fields) # ['red', 'green', 'blue']
Choose the regular expression to match the separators your input actually uses; unlike split(), this approach interprets the separator as a pattern.
How is splitting lines different?
Use splitlines() for line boundaries. It is designed for line-oriented text and differs from split('n') in how it handles empty input and a terminal line break. If the goal is to process lines rather than a particular newline character, choose splitlines().
Quick Recap
Which method should you choose?
| Goal | Method | Behavior |
|---|---|---|
| Get string sequence elements | list(text) |
Returns individual string elements; not a general grapheme-cluster splitter. |
| Split at one exact delimiter | text.split(sep) |
Uses the entire separator string; repeated separators can produce empty fields. |
| Split on whitespace runs | text.split() |
Collapses whitespace runs and omits empty fields at the ends. |
| Split at pattern alternatives | re.split(pattern, text) |
Uses a regular-expression pattern for separators. |
| Split at the first match and retain it | text.partition(sep) |
Returns the text before, the separator, and the text after as a tuple. |
| Limit splits from the right | text.rsplit(sep, maxsplit) |
Applies the split limit starting from the right. |
| Divide into lines | text.splitlines() |
Uses line-boundary behavior rather than splitting only on n. |
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




