Software

How to Convert a List to a String in Python

Use separator.join(list) to turn a list of strings into one string. Fix the TypeError for numbers with map(str) and avoid common pitfalls. Real outputs.

Use str.join(): call it on the separator and pass the list. ", ".join(["apples", "pears", "plums"]) returns 'apples, pears, plums'. Every item must already be a string; for numbers or mixed values, convert first with ", ".join(map(str, items)).

The basic patterns

Real outputs from Python 3.14.3:

fruits = ["apples", "pears", "plums"]

", ".join(fruits)      # 'apples, pears, plums'
"".join(["a", "b", "c"])  # 'abc'
"\n".join(fruits)      # 'apples\npears\nplums'  (one per line)
", ".join([])          # ''  (empty list gives an empty string)

The method belongs to the separator, which reads backwards at first: separator.join(list), not list.join(separator).

Numbers and mixed types

join() does not convert for you:

>>> ", ".join(["apples", 3, "pears"])
TypeError: sequence item 1: expected str instance, int found
>>> ", ".join(map(str, ["apples", 3, "pears"]))
'apples, 3, pears'
>>> ", ".join(str(x) for x in [1.5, None, True])
'1.5, None, True'

The error message tells you the index of the first non-string item (item 1) and its type. Try your own list:

Try itEnter list items and a separator to see what join() returns or raises.

', '.join(['apples', 3, 'pears']) raises

', '.join(map(str, items))
'apples, 3, pears'
TypeError: sequence item 1: expected str instance, int found

Formatting the items

Use a generator expression with an f-string when the items need formatting:

" ".join(f"{p:.2f}" for p in [3, 4.5, 10])   # '3.00 4.50 10.00'

For natural-language lists, join all but the last item:

", ".join(fruits[:-1]) + " and " + fruits[-1]   # 'apples, pears and plums'

What not to use

  • str(my_list) gives the list’s representation, brackets and quotes included: "['apples', 'pears', 'plums']". Useful for debugging, not for output.
  • += in a loop works but builds a new string on every iteration; join() is clearer and faster for many items.
  • Joining with commas to make CSV breaks as soon as a value contains a comma or quote. Use the csv module, which quotes correctly: writing ["Ada, Countess", 'say "hi"', 3] produced '"Ada, Countess","say ""hi""",3\r\n' in our run.

Going the other way

"apples, pears, plums".split(", ") turns the string back into a list. To turn the pieces into numbers, combine with int(): [int(x) for x in "1,2,3".split(",")] gives [1, 2, 3]. The string-to-int guide covers what int() accepts and how to handle bad input. For structured data, the JSON to CSV converter shows correct CSV quoting on real records.

Sources

  1. str.join — Python documentation
  2. csv — CSV File Reading and Writing — Python documentation

How we made this

Reproduced in a local lab. All examples were run in Python 3.14.3 and the printed results pasted verbatim. The interactive example models str.join and str() for strings, integers, floats, booleans and None.

Performed by Claude, an AI assistant working in the BinConvert repository (Python 3.14.3), November 16, 2026.

This article was drafted with AI assistance. Every example, calculation and command output on this page was re-run or checked before release; each example was re-run and the output compared. Review: automated test suite and source check, November 16, 2026.

Spotted an error? Tell us and we will correct it.

Copied to clipboard!