How do I convert a list to a string in Python?
Short answer: Call join() on the separator you want and pass it the list: ", ".join(pets) turns ["Dog", "Cat", "Parrot"] into "Dog, Cat, Parrot". join() only accepts strings, so if the list has numbers or other types, convert them first with ", ".join(map(str, items)).
join() is a string method. You write the separator first and the list inside the parentheses, which surprises many people who expect list.join(). It puts the separator only between the items, never at the start or at the end, and it returns a new string without changing your list.
join() works directly with a list of strings. With numbers it raises a TypeError, and map(str, ...) converts them first.
Python list to string at a glance
| What you have | Code | Result |
|---|---|---|
| A list of strings | ", ".join(pets) | "Dog, Cat, Parrot" |
| No separator | "".join(["a", "b", "c"]) | "abc" |
| One item per line | "\n".join(lines) | Each item on its own line |
| Numbers or mixed types | ", ".join(map(str, items)) | "1, 9, 42" |
| Format each item | ", ".join(f"{p:.2f}" for p in prices) | "9.50, 12.00" |
Skip None values | ", ".join(str(x) for x in items if x is not None) | None items are left out |
| Just print it | print(*items, sep=", ") | Prints 1, 9, 42 |
| Keep the brackets | str(items) | "[1, 9, 42]" |
Convert a list of strings with join()
The syntax is separator.join(list). The separator can be any string, including an empty one:
pets = ["Dog", "Cat", "Parrot"]
print(", ".join(pets)) # Dog, Cat, Parrot
print(" ".join(pets)) # Dog Cat Parrot
print("".join(pets)) # DogCatParrot
print(" | ".join(pets)) # Dog | Cat | Parrotjoin() accepts any iterable of strings, not only lists. It works the same with tuples, sets and generators:
print("-".join(("2026", "11", "09"))) # 2026-11-09
print("".join(reversed("python"))) # nohtypConvert a list of numbers or mixed types
If any item is not a string, join() stops with an error:
nums = [1, 9, 42]
", ".join(nums)
# TypeError: sequence item 0: expected str instance, int foundThe message tells you the position of the first item that is not a string (item 0) and its type (int). Convert every item with map():
nums = [1, 9, 42]
print(", ".join(map(str, nums))) # 1, 9, 42map(str, nums) applies str() to each item. A generator expression does the same and lets you change each item on the way:
prices = [9.5, 12, 3.25]
print(", ".join(f"{p:.2f}" for p in prices)) # 9.50, 12.00, 3.25
mixed = ["Ana", 31, None, True]
print(", ".join(str(x) for x in mixed if x is not None)) # Ana, 31, TrueWithout the if, None becomes the text "None", which is rarely what you want in a sentence or a CSV line.
Convert a list to a string with a for loop
You can also build the string yourself:
pets = ["Dog", "Cat", "Parrot"]
result = ""
for i, pet in enumerate(pets):
if i > 0:
result += ", "
result += pet
print(result) # Dog, Cat, ParrotIt works, but you have to handle the separator by hand, and each += creates a new string. Use join() in real code and keep the loop for when each item needs complex logic, and even then collect the pieces in a list and join them at the end.
Other ways: str(), print() and json.dumps()
str(items)keeps the brackets and quotes:str(["a", "b"])returns"['a', 'b']". It is useful for logs, not for text a person reads.print(*items, sep=", ")prints the items with a separator without building a string. It accepts numbers directly.json.dumps(items)returns valid JSON, such as'["Dog", "Cat"]', which is the right choice to save the list or send it to an API.
import json
pets = ["Dog", "Cat"]
print(str(pets)) # ['Dog', 'Cat']
print(*pets, sep=", ") # Dog, Cat
print(json.dumps(pets)) # ["Dog", "Cat"]Convert a string back to a list
split() is the inverse of join():
text = "Dog, Cat, Parrot"
pets = text.split(", ") # ['Dog', 'Cat', 'Parrot']
words = "a b c".split() # ['a', 'b', 'c'], splits on any whitespace
letters = list("abc") # ['a', 'b', 'c']To go back to numbers, convert each piece: [int(n) for n in "1,9,42".split(",")] returns [1, 9, 42].
