How to Join a List of Strings in Python with str.join
A list of words is easy to build, but printing it gives brackets and quotes. str.join glues the strings together with any separator you choose: a comma, a space, a newline or nothing. This guide shows three separators and the one error to expect, with real output from Python 3.15.2.
Syntax
<separator>.join(<strings>)
| Part | What it means |
|---|---|
<separator> | The text placed between the items, such as ", ". It can be empty: "" |
<strings> | A list, tuple or other iterable of strings |
Python's documentation: "Return a string which is the concatenation of the strings in iterable. A TypeError will be raised if there are any non-string values in iterable, including bytes objects. The separator between elements is the string providing this method."
Prerequisites
- uv and Python. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with
uv init.
Step 1: Write the Script
words = ["tent", "stove", "lantern"]
print(", ".join(words))
print(" | ".join(words))
print("".join(["a", "b", "c"]))

Step 2: Run It
uv run python join_words.py
tent, stove, lantern
tent | stove | lantern
abc

The separator appears only between items: there's no comma after lantern. An empty separator runs the strings together.
When the List Holds Numbers
join accepts strings only:
numbers = [1, 2, 3]
print(", ".join(numbers))
uv run python join_numbers.py
Traceback (most recent call last):
File "/Users/you/source/python-basics/join_numbers.py", line 3, in <module>
print(", ".join(numbers))
~~~~~~~~~^^^^^^^^^
TypeError: sequence item 0: expected str instance, int found
Item 0, the 1, isn't a string. Convert each item first, for example with a list comprehension: ", ".join([str(n) for n in numbers]) gives 1, 2, 3.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Writing words.join(", ") | AttributeError: 'list' object has no attribute 'join' | Call it on the separator: ", ".join(words) |
| Joining numbers | TypeError: sequence item 0: expected str instance, int found | Convert them with str() first |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| The words run together | The separator is "" | Use " " or ", " |
FAQ
How do I put each item on its own line?
Use a newline as the separator: "\n".join(words).
Why not add the strings with + in a loop?
You can, but join builds the result in one step and never adds a stray separator at the end.
Conclusion
", ".join(words) turned ["tent", "stove", "lantern"] into tent, stove, lantern, a pipe and an empty string worked the same way, and a list of numbers raised the TypeError until each item was a string.
Additional Resources
- str.join — joining strings with a separator.
