October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Split a Python String into Characters or Fields

Use list() for a string’s sequence elements, split(sep) for an exact delimiter, and split() for whitespace. Learn how to handle repeated separators, multiple patterns, and limited splits.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

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:

"".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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
"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.

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.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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().

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.