Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →For simple text with commas between values, call split(','): text.split(',') returns a Python list. Trim each result with strip() if values may have spaces around them. If the input follows CSV quoting rules or values can contain commas, use Python’s standard-library csv reader instead.
Split a simple comma-separated string
Use the string method split(',') when commas are literal separators and fields do not need quoting:
text = "apple,banana,cherry"
items = text.split(',')
print(items)
# ['apple', 'banana', 'cherry']
The explicit comma tells Python where to divide the string. The result is a list of strings; it does not convert values to numbers or other types. See the Python 3.14.8 documentation for str.split.
Trim spaces around each value
If spaces around the values are incidental, strip each part after splitting:
#1 Best Overall
text = "apple, banana ,cherry"
items = [part.strip() for part in text.split(',')]
# ['apple', 'banana', 'cherry']
strip() removes whitespace at the beginning and end of each value. It leaves whitespace inside a value untouched. Do not use text.split() for comma-separated input: without an explicit separator, split() separates on whitespace instead.
Decide what empty fields mean
With an explicit comma separator, Python splits at every comma and preserves empty fields as empty strings. For example, '1,,2'.split(',') returns ['1', '', '2']; a trailing comma produces a final empty string, and ''.split(',') returns ['']. This behavior can preserve missing positions in your data. If empty fields should instead be discarded, filter them deliberately:
Rank #2
items = [part.strip() for part in text.split(',') if part.strip()]
That filter removes both empty fields and values containing only whitespace. Keep it out if those fields carry meaning. The Python documentation describes how explicit separators handle consecutive delimiters in its str.split reference.
Use a CSV reader when fields can contain commas
split(',') does not interpret quotation marks. Given one,"two, three",four, it also splits at the comma inside the quoted value, so it cannot correctly parse that CSV row. For CSV-formatted text, use the standard-library csv module:
import csv
text = 'one,"two, three",four'
items = next(csv.reader([text]))
# ['one', 'two, three', 'four']
The example wraps the text in a one-element iterable because csv.reader reads records from an iterable of lines. For files with multiple rows, pass the file object to csv.reader and process its records rather than treating the whole file as one string. Consult the Python 3.14.8 csv reading and writing documentation for the reader’s behavior and usage.
Choose the right method
| Input | Use | Why |
|---|---|---|
| Plain values separated by literal commas | text.split(',') |
Directly splits at each comma. |
| Plain values with incidental surrounding spaces | [part.strip() for part in text.split(',')] |
Splits at commas, then trims each value’s boundaries. |
| CSV fields with quotes or embedded commas | csv.reader |
Parses CSV quoting instead of splitting every comma. |
Both approaches use Python functionality: split is a built-in string method, and csv is part of the standard library.
Quick Recap
Best Value
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.




