How to Convert a List to a String in Python

Short answer
Use ", ".join(items) to glue a list of strings into one string. If the list holds numbers, convert them first: ", ".join(map(str, numbers)).

You often need a list as one piece of text, for a sentence, a CSV line, a log message or a file name. The standard tool is str.join(): you choose the separator and call join() on it, passing the list.

The one rule to remember is that every item must already be a string. Anything else, such as integers, must be converted first. Knowing this saves you from the most common error on this topic.

Quick facts
Syntaxseparator.join(iterable)
ReturnsA new string
Items must beStrings (convert numbers with str())
Oppositetext.split()

Join a list of strings with join()

The separator goes before the dot, the list goes inside the brackets. Use "" for no separator.

Python
words = ["learn", "python", "today"]
print(" ".join(words))
print("-".join(words))
print("".join(words))

Join a list of numbers or mixed values

join() rejects non-strings, so convert each item. map(str, numbers) is short, and a list comprehension is equally good.

Python
numbers = [3, 7, 12]
print(", ".join(map(str, numbers)))
print(", ".join(str(n) for n in numbers))

Other ways to turn a list into a string

GoalCodeResult for ['a', 'b']
Words joined with space" ".join(items)'a b'
No separator"".join(items)'ab'
One item per line"\n".join(items)'a\nb'
Python's own text formstr(items)"['a', 'b']"
Print items without bracketsprint(*items)a b

str(list) is not the same as join()

Calling str() on a list gives its representation, including brackets and quotes, which is meant for debugging. If you want clean text, use join(). The reverse operation is explained in converting a string to a list, and you can read more about the method in the list basics lesson.

Examples you can run

Press Run, then edit the code and run it again.

Make a comma-separated shopping line

A normal join with a readable separator.

Make a comma-separated shopping line
cart = ["pen", "notebook", "ruler"]
print("Cart: " + ", ".join(cart))
Expected outputCart: pen, notebook, ruler

Join numbers after converting them

Each number becomes a string before joining.

Join numbers after converting them
scores = [88, 92, 79]
line = " | ".join(str(s) for s in scores)
print(line)
Expected output88 | 92 | 79

Edge cases: empty list and a single item

No trailing separator appears, and an empty list gives an empty string.

Edge cases: empty list and a single item
print(repr(", ".join([])))
print(repr(", ".join(["only"])))
print(str(["a", "b"]))
Expected output''
'only'
['a', 'b']

Common mistakes

Joining numbers directly

✗ Wrong

nums = [1, 2, 3]
print(",".join(nums))
TypeError: sequence item 0: expected str instance, int found

✓ Right

nums = [1, 2, 3]
print(",".join(map(str, nums)))

Convert items to strings first with map(str, nums).

Calling join on the list

✗ Wrong

words = ["a", "b"]
print(words.join("-"))
AttributeError: 'list' object has no attribute 'join'

✓ Right

words = ["a", "b"]
print("-".join(words))

join() is a string method. Put the separator first: "-".join(words).

How to Convert a List to a String in Python: questions people ask

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

Use " ".join(my_list) when the items are strings, choosing any separator you like between the quotes.

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

Convert each integer with str() and then join: "".join(map(str, [1, 2, 3])) gives "123".

What is the difference between str(list) and join()?

str(list) returns the list's printed form with brackets and quotes, while join() builds clean text with your chosen separator.

Keep learning

Step-by-step lessons:
Python ListsPython String MethodsPython Casting

Related:
Python String join() MethodHow to Convert a String to a List in PythonHow to Convert an Int to a String in PythonPython String split() Method

More in converting data:
How to Convert a String to an Int in PythonHow to Convert an Int to a String in PythonHow to Convert a String to a List in PythonHow to Convert a String to a Float in PythonHow to Convert a Float to an Int in PythonHow to Convert a List to a Dictionary in PythonHow to Convert a Tuple to a List in PythonHow to Convert a String to a Datetime in Python See all →