To split comma-separated text into a Python list, call split(',') on the string. A Python list is already a sequence of items, so the splitting step applies to the text that holds the commas, not to the list. The rest of this article covers the exact behavior of that call, the edge cases that produce surprising results, and the options for limiting or refining the split.
Start with the input: a string, not a list
Most people who search for this task have one of two situations in mind:
- A string such as
"red,green,blue"that needs to become['red', 'green', 'blue']. This is whatsplit(',')handles. - A list that already exists, which is already split into elements. There is nothing to split. If you need the elements joined into a comma-separated string, that is the reverse operation,
','.join(my_list).
The method only works on strings. If you call it on a value that is already a list, Python raises an AttributeError, because lists do not have a split method.
The basic split
Pass the comma as the separator argument to str.split():
Recommended Free Tools
#1 Best Overall
text = "red,green,blue"
items = text.split(',')
print(items) # ['red', 'green', 'blue']
The comma is a literal delimiter. Python removes each comma and returns the pieces between them as strings. The method returns a new list and leaves the original string unchanged.
Edge cases that change the result
Empty fields are kept
When you give an explicit separator, Python keeps every field, including empty ones. Two adjacent commas produce an empty string, and a trailing comma produces an empty string at the end:
print('a,,b,'.split(',')) # ['a', '', 'b', '']
The method does not remove empty values for you. If your data can contain blank fields, decide what to do with them. You can filter them out with a list comprehension:
Rank #2
items = [part for part in 'a,,b,'.split(',') if part]
print(items) # ['a', 'b']
Keep the empty strings when their position matters, for example in fixed-column records where a blank field means “no value.” Filter them when blanks are just formatting noise.
Spaces after commas stay in the output
The split happens exactly at the comma character. A space after a comma becomes part of the next element:
print("red, green, blue".split(',')) # ['red', ' green', ' blue']
To remove that leading whitespace, strip each item:
items = [part.strip() for part in "red, green, blue".split(',')]
print(items) # ['red', 'green', 'blue']
Omitting the separator splits on whitespace
If you call split() with no argument, Python does not split on commas. It splits on runs of whitespace, treats consecutive whitespace as one delimiter, and drops empty strings at the start and end:
print("red,green blue".split()) # ['red,green', 'blue']
This is a common source of confusion. If the goal is commas, always pass ',' explicitly.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Limit the number of splits
The optional maxsplit argument sets how many splits occur. The default, -1, means no limit. A positive value caps the number of splits, so the result contains at most maxsplit + 1 elements. The remainder of the string stays together in the last element:
line = "name,role,notes,with,commas"
print(line.split(',', 1)) # ['name', 'role,notes,with,commas']
Use this when only the first field or first few fields have a fixed meaning, and the rest of the line is free text that may itself contain commas.
Splitting from the right with rsplit()
rsplit() accepts the same arguments but applies the limit from the right. Compare the two results:
line = "name,role,notes,with,commas"
print(line.split(',', 1)) # ['name', 'role,notes,with,commas']
print(line.rsplit(',', 1)) # ['name,role,notes,with', 'commas']
Choose rsplit() when the fixed-meaning fields are at the end of the line, such as a trailing numeric value.
Best Value
Compare the choices at a glance
Call on "a,,b, c" |
Result | When to use it |
|---|---|---|
split(',') |
['a', '', 'b', ' c'] |
Standard comma-separated text; empty fields matter |
split(',', 1) |
['a', ',b, c'] |
Only the first field is structured |
rsplit(',', 1) |
['a,', 'b, c'] |
Only the last field is structured |
split() |
['a,,b,', 'c'] |
Whitespace-separated text, not commas |
When a plain comma split is not enough
A plain split(',') treats every comma as a delimiter. It does not understand quoting, so a value such as "Smith, John",42 breaks into three pieces. For CSV files that contain quoted fields, use the csv module from the standard library instead of hand-written splitting.
If the text uses more than one separator, such as commas and semicolons, pass a pattern to re.split() from the re module:
import re
print(re.split(r'[,;]', 'red,green;blue')) # ['red', 'green', 'blue']
Note that re.split() treats the pattern as a regular expression, so it has its own rules for empty matches and special characters. Escape any characters that have meaning in regular expressions.
Reference for this behavior
The behavior described above comes from the str.split(sep=None, maxsplit=-1) entry in the Python Software Foundation’s Built-in Types documentation, which covers explicit-separator and whitespace splitting, empty fields, and the rsplit() difference. The reference used for this article is the Python 3.14 documentation as published in October 2026: https://docs.python.org/3/library/stdtypes.html?highlight=discard. Check the same section in your installed version if you are working on an older release.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsQuick Recap
“
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.




