How to Convert a String to a List in Python

To convert a Python string to a list, use split(): "TX,CA,NY".split(",") gives ['TX', 'CA', 'NY'], and with no argument it splits on whitespace. To get one item per character, use list(text):

words = text.split()       # list of words
chars = list(text)         # list of characters

These snippets use US cities, state codes and prices, run on Python 3.12.5.

You’ll learn split() and list(), comma-separated values with spaces and numbers, strings that already look like a list, and multiple delimiters.

Convert a string to a list with split() and list()

split() with no argument treats any run of spaces as one separator. Pass a separator and it splits on exactly that, which can leave empty strings:

sentence = "Ship to Austin  Texas today"
print(sentence.split())                 # any run of whitespace
print(sentence.split(" "))              # exactly one space: note the empty string
print("TX,CA,NY,FL".split(","))
print("2026-10-10 09:30:00".split(" ", 1))   # maxsplit=1
print(list("Ohio"))                     # one item per character

Output:

['Ship', 'to', 'Austin', 'Texas', 'today']
['Ship', 'to', 'Austin', '', 'Texas', 'today']
['TX', 'CA', 'NY', 'FL']
['2026-10-10', '09:30:00']
['O', 'h', 'i', 'o']
Command Prompt output of Python split with no argument, split on a space, split on commas, maxsplit and list of characters
split() collapses the double space; split(" ") keeps an empty string for it.

maxsplit stops after that many splits, handy for a date and time. More whitespace cases are in splitting a string by whitespace in Python.

Split a comma-separated string into numbers or clean words

Data from a form or CSV usually has stray spaces. float() and int() ignore them, but for text, strip each piece:

raw = "19.99, 5.25 ,102.00,  7.50"
parts = raw.split(",")
print(parts)                                       # spaces stay attached
prices = [float(p) for p in parts]                 # float() ignores the spaces
print(prices, "total:", f"${sum(prices):.2f}")

tags = [t.strip() for t in " python , data , web ".split(",")]
print(tags)

print("".split(","), "".split())                   # empty string: [''] vs []

Output:

['19.99', ' 5.25 ', '102.00', '  7.50']
[19.99, 5.25, 102.0, 7.5] total: $134.74
['python', 'data', 'web']
[''] []
Command Prompt output of Python splitting a comma-separated price string into floats with a total, stripping tags, and splitting empty strings
Prices convert straight to floats; tags need strip(); an empty string splits into [''], not an empty list.

That last line bites in real code: "".split(",") gives one empty item. Check for an empty string first. Converting each piece is covered in converting a string to an integer in Python.

How do you convert a string that looks like a list?

Sometimes the string is already "['Austin', 'Denver']", for example from a log or a CSV cell. ast.literal_eval() parses it safely. json.loads() only works with double quotes:

import ast
import json

text = "['Austin', 'Denver', 'Tampa']"
print(ast.literal_eval(text), type(ast.literal_eval(text)).__name__)

try:
    json.loads(text)
except json.JSONDecodeError as err:
    print("JSONDecodeError:", err.msg)

print(json.loads('["Austin", "Denver", "Tampa"]'))   # JSON needs double quotes

Output:

['Austin', 'Denver', 'Tampa'] list
JSONDecodeError: Expecting value
['Austin', 'Denver', 'Tampa']
Command Prompt output of Python ast.literal_eval parsing a single-quoted list string, json.loads failing, and json.loads on a double-quoted list
literal_eval returns a real list; JSON rejects the single quotes.

Never use eval() for this; it runs any code in the string. If the data is JSON, I’d write it with json.dumps() in the first place, as in converting a string to CSV in Python.

Split a string with multiple delimiters using re

When the separators vary, re.split() takes a pattern. re.findall() pulls out only the parts you want, and splitlines() handles line breaks:

import re

line = "Austin;Denver, Tampa|Miami"
print(re.split(r"[;,|]\s*", line))            # several delimiters at once
print(re.findall(r"\d+", "Order A-1001 shipped 3 items, $49 total"))
print("line one\nline two\r\nline three".splitlines())

Output:

['Austin', 'Denver', 'Tampa', 'Miami']
['1001', '3', '49']
['line one', 'line two', 'line three']
Command Prompt output of Python re.split with several delimiters, re.findall extracting numbers, and splitlines
Four cities from three different separators, the numbers from a sentence, and three lines.

Patterns are covered in more depth in splitting a string with regex in Python.

Which string to list method should you use?

Match the method to what your string looks like. If you need to go the other way later, see building strings from variables in Python.

StringUseResult
Words separated by spacess.split()List of words
Values with one separators.split(",")List of strings
Characterslist(s)One item per character
Looks like a Python listast.literal_eval(s)The real list
Mixed separatorsre.split(pattern, s)List of strings

Keep going with these string guides:

Frequently asked questions

How do I convert a string to a list in Python?

Use s.split() for words, s.split(",") for comma-separated values, or list(s) for characters.

How do I convert a string to a list of characters?

Pass it to list(): list("Ohio") gives ['O', 'h', 'i', 'o'].

Why does split give empty strings?

With an explicit separator, each separator splits, so doubled separators leave ''. Use split() with no argument for whitespace.

How do I convert “[‘a’, ‘b’]” into a list?

Use ast.literal_eval(s). It safely parses Python literals; don’t use eval().

How do I convert a comma-separated string to integers?

[int(x) for x in s.split(",")]. int() ignores surrounding spaces.

Where is str.split documented?

See str.split() in the Python docs.