4Geeks chosen to deliver AI education in the Bahamas alongside Harvard, Oxford, and Columbia.See more

Convert List to String in Python

By 4Geeks

Turn any Python list into text with join(), even when it mixes numbers, None and other types.

7 min readLast updated
Python list to string icon

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 haveCodeResult
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 itprint(*items, sep=", ")Prints 1, 9, 42
Keep the bracketsstr(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:

python
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 | Parrot

join() accepts any iterable of strings, not only lists. It works the same with tuples, sets and generators:

python
print("-".join(("2026", "11", "09")))  # 2026-11-09
print("".join(reversed("python")))     # nohtyp

Convert a list of numbers or mixed types

If any item is not a string, join() stops with an error:

python
nums = [1, 9, 42]
", ".join(nums)
# TypeError: sequence item 0: expected str instance, int found

The 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():

python
nums = [1, 9, 42]
print(", ".join(map(str, nums)))  # 1, 9, 42

map(str, nums) applies str() to each item. A generator expression does the same and lets you change each item on the way:

python
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, True

Without 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:

python
pets = ["Dog", "Cat", "Parrot"]
result = ""
for i, pet in enumerate(pets):
    if i > 0:
        result += ", "
    result += pet
print(result)  # Dog, Cat, Parrot

It 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.
python
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():

python
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].

Career · AI Engineering

You can turn lists into text, now build something with it

From zero to junior AI Engineer: Python, AI agents and RAG with mentors and real projects.

Convert lists to strings with AI

An AI assistant such as ChatGPT, Claude or GitHub Copilot can write the exact join() for your data and explain an error. Give it a sample of your list and the result you want. These three prompts are ready to copy.

1. Get the exact code for your data

I have this Python list: [paste a few items, e.g. ["Ana", 31, None, 4.5]]
I want this string: [e.g. "Ana, 31, 4.50"]
Write the shortest readable code with join() and explain each part.
Tell me what happens with None values and numbers.

2. Explain a TypeError

My Python code fails with:
TypeError: sequence item 2: expected str instance, int found
This is the line: [paste the line with join()]
Explain why it happens and give me two ways to fix it.

3. Build a CSV line or a sentence

I have a list of dictionaries in Python: [paste 2 or 3 of them]
Turn each one into a CSV line with the fields name, email and age,
separated by commas, and join all the lines with a line break.
Tell me when I should use the csv module instead of join().

Check the result with your real data. Run the code with a list that has numbers, None and empty strings before you trust it.

Join a list of lists and other special cases

Nested lists. join() does not flatten anything. Join each inner list first, then the results:

python
table = [["a", "b"], ["c", "d"]]
print("\n".join(", ".join(row) for row in table))
# a, b
# c, d

A sentence with "and". Join every item except the last one:

python
names = ["Ana", "Luis", "Marta"]
text = ", ".join(names[:-1]) + " and " + names[-1]
print(text)  # Ana, Luis and Marta

With a single item, names[:-1] is empty and the result is " and Ana", so check len(names) first in real code.

Quotes around each item. Use an f-string inside the generator: ", ".join(f'"{n}"' for n in names) returns "Ana", "Luis", "Marta".

Very long lists. join() calculates the final size once and copies each item a single time, so it stays fast with thousands of items. Adding with += in a loop can get slower as the string grows.

Learn with a mentor

Master Python data types, then build AI with them

In the 4Geeks AI Engineering career program you start with no experience and finish with AI agents and RAG systems in your portfolio.

Common errors when you convert a list to a string

What you seeWhy it happensFix
TypeError: sequence item 0: expected str instance, int foundThe list has numbers or other non-string items", ".join(map(str, items))
AttributeError: 'list' object has no attribute 'join'You wrote items.join(", ")Put the separator first: ", ".join(items)
The result has brackets and quotes, like ['a', 'b']You used str(items)Use join()
The text says NoneThe list contains NoneFilter it out: str(x) for x in items if x is not None
The result starts with a separatorA loop added the separator before the first itemUse join(), which only puts it between items
TypeError: can only join an iterableYou passed a number or None instead of a listCheck the variable you pass to join()
Free download

Every list-to-string recipe in a 2-page cheat sheet

join() recipes for strings, numbers and None, special cases like nested lists and CSV lines, the most common errors and prompts for ChatGPT, Claude or Copilot. Free, in PDF.

Python list to string cheat sheet

2 pages · PDF · 4Geeks

  • 12 ready-to-copy join() recipes
  • How to handle numbers, None and nested lists
  • The 5 most common errors and prompts to fix them with AI

Get it free

Your PDF right away

Frequently asked questions about converting a list to a string in Python

Want to go from Python basics to building AI agents, with real projects and mentors?

See the AI Engineering program