In everyday Python, “join a list” usually means either turning a list of strings into one string or merging lists into a longer list. Those are different operations. This page centers on str.join, which the docs describe as returning a string built from the strings in an iterable with your separator between them (and raising TypeError if any element is not a string). List-to-list tools such as +, extend(), and itertools.chain come second.
items = ["red", "green", "blue"]
print(" ".join(items))That prints red green blue. The separator (" ") is the string you call join on; the iterable holds the pieces.
Tested on: Python 3.13.3; kernel 6.14.0-37-generic.
Best way to join a list in Python
| User wants | Use |
|---|---|
| Join list items into a string | ", ".join(items) (strings only) |
| Join list of numbers into a string | ", ".join(map(str, numbers)) |
| Join two lists into one list | list1 + list2 (new list) |
| Add one list into another | list1.extend(list2) (mutates first list) |
| Join many lists lazily | itertools.chain(*lists) |
| Flatten one level of nested lists | itertools.chain.from_iterable(nested) (see Python flatten list for deeper patterns) |
Python join list syntax
separator_string.join(iterable_of_strings)join is a string method: the separator is str, the iterable must yield str values. There is no list.join() API.
Join list of strings using join()
items = ["red", "green", "blue"]
print(" ".join(items))You should see red green blue.
Join list with comma separator
items = ["red", "green", "blue"]
print(",".join(items))
print(", ".join(items))The first line prints red,green,blue; the second prints red, green, blue.
Join list with space separator
words = ["hello", "world"]
print(" ".join(words))You should see hello world.
Join list with newline separator
lines = ["first", "second", "third"]
print("\n".join(lines))Running it prints three lines (first, then second, then third).
Join list of numbers
Numbers are not strings—convert before join:
numbers = [1, 2, 3]
print(", ".join(map(str, numbers)))You should see 1, 2, 3.
Join list with mixed data types
Cast each element to str (or normalize first) so join never sees non-strings:
mixed = ["id", 42, True]
print(" | ".join(str(x) for x in mixed))Expect id | 42 | True.
Fix TypeError when joining a list
TypeError: sequence item 0: expected str instance, int found means the iterable still holds non-strings.
numbers = [1, 2, 3]
result = ", ".join(map(str, numbers))
print(result)That prints 1, 2, 3. For richer objects, build the string you want explicitly instead of relying on str() defaults.
Join two lists in Python
Use + when you want a new combined list; use extend when you want to mutate the first list in place:
list1 = [1, 2]
list2 = [3, 4]
print(list1 + list2)
list1.extend(list2)
print(list1)The first print shows [1, 2, 3, 4] from a new list; list1 is still [1, 2] until extend runs. After extend(list2), list1 becomes [1, 2, 3, 4] while list2 remains [3, 4]. For more patterns, see Python concatenate lists.
Join list of lists in Python
For a single level of nesting, itertools.chain.from_iterable yields each inner item lazily, then you can join if those items are strings:
from itertools import chain
rows = [["a", "b"], ["c", "d"]]
print(",".join(chain.from_iterable(rows)))That prints a,b,c,d. Irregular trees or deeper nesting belong in a flattening workflow—use the dedicated Python flatten list guide instead of duplicating long recipes here.
join() vs + vs extend()
| Tool | Returns | Typical use |
|---|---|---|
sep.join(strings) |
One str |
Build text from string pieces |
a + b |
New list |
Combine two lists immutably |
a.extend(b) |
None (mutates a) |
Append all items from b into a |
For strings, repeated result += chunk inside a tight loop allocates often; collecting pieces in a list and calling join once is usually faster and clearer.
Common mistakes when joining lists in Python
- Writing
items.join(", ")—the separator string must be the receiver:", ".join(items). - Passing integers or objects straight into
join—convert withmap(str, ...)or comprehensions first. - Using
joinwhen you meant to merge two lists—joinbuilds text, not a longer list. - Building big strings with
+in a loop—prefer a list buffer plus onejoin. - Expecting a return value from
extend()—it always returnsNone; the first list grows in place. - Calling
str(my_list)when you wanted delimiter-separated output—you get bracket notation, not a tidy join. - Re-embedding a full flattening tutorial here—use the dedicated flatten-list guide linked in the table and nested-list section when nesting is the real problem.
Python join list quick reference table
| Goal | Pattern |
|---|---|
| CSV-like string | ",".join(vals) |
| Human spacing | ", ".join(vals) or " ".join(vals) |
| Multiline text | "\n".join(lines) |
| Numeric list to text | ", ".join(map(str, nums)) |
| New combined list | a + b |
| In-place merge | a.extend(b) |
| One-level flatten then join | sep.join(chain.from_iterable(groups)) |
Summary
Call separator.join(iterable) when every element is already a string; convert with map(str, ...) or explicit string formatting when you start from numbers or mixed types, because join raises TypeError otherwise. Comma, space, and newline joins are the same pattern with a different separator. When readers say “join lists” but mean list concatenation, switch to + or extend, and reach for itertools.chain or the flatten-list guide linked above when nested structure—not delimiter choice—is the hard part.

