Python String join() Method
The Python string join() method combines multiple strings into one string.
It is useful when you have a list or tuple of text values and want to join them with a separator such as a space, comma, dash, or nothing at all.
A key rule to remember is this:
- You call
join()on the separator string - Every item you join must already be a string
Quick answer #
words = ["Python", "is", "fun"]
result = " ".join(words)
print(result)
Output:
Python is fun
Use join() on the separator string. Every item in the iterable must be a string.
What join() does #
join() combines multiple strings into one string.
Important points:
- It uses the string before
.join()as the separator - Common separators are:
" "for spaces", "for commas"-"for dashes""for no separator
- It returns a new string
- It does not change the original list or tuple
Example:
words = ["red", "green", "blue"]
result = ", ".join(words)
print(result)
print(words)
Output:
red, green, blue
['red', 'green', 'blue']
The list stays the same. join() creates a new string.
Basic syntax #
The basic syntax is:
separator.join(iterable)
Parts of the syntax #
separatoris a string such as" ",", ","-", or""iterableis usually a list or tuple of strings- All items in the iterable must be strings
Example:
names = ["Ana", "Ben", "Cara"]
result = " | ".join(names)
print(result)
Output:
Ana | Ben | Cara
If you are still getting comfortable with strings, see Python strings explained: basics and examples.
Simple examples #
Join words with a space #
words = ["Python", "is", "easy"]
result = " ".join(words)
print(result)
Output:
Python is easy
Join values with a comma #
items = ["apples", "bananas", "oranges"]
result = ", ".join(items)
print(result)
Output:
apples, bananas, oranges
Join characters with an empty string #
letters = ["P", "y", "t", "h", "o", "n"]
result = "".join(letters)
print(result)
Output:
Python
Show that join() returns the result #
words = ["one", "two", "three"]
joined_text = "-".join(words)
print(joined_text)
Output:
one-two-three
Using different separators #
The separator controls what appears between each item.
" ".join(...) adds spaces #
words = ["hello", "world"]
print(" ".join(words))
Output:
hello world
", ".join(...) creates comma-separated text #
colors = ["red", "blue", "green"]
print(", ".join(colors))
Output:
red, blue, green
This is useful when building simple CSV-style text.
"-".join(...) is useful for slugs or IDs #
parts = ["python", "string", "join"]
print("-".join(parts))
Output:
python-string-join
"".join(...) joins with no separator #
chars = ["A", "B", "C"]
print("".join(chars))
Output:
ABC
What types of values work #
join() works when every item is already a string.
This works #
values = ["10", "20", "30"]
print(", ".join(values))
Output:
10, 20, 30
Numbers do not work directly #
values = [1, 2, 3]
print(", ".join(values))
This causes a TypeError because the list contains integers, not strings.
To fix it, convert the values first:
values = [1, 2, 3]
result = ", ".join(map(str, values))
print(result)
Output:
1, 2, 3
If you need a clearer explanation of string conversion, see Python str() function explained.
None values do not work directly #
values = ["apple", None, "banana"]
print(", ".join(values))
This also causes a TypeError.
One fix is to convert values to strings:
values = ["apple", None, "banana"]
result = ", ".join(map(str, values))
print(result)
Output:
apple, None, banana
Be careful with this approach. Sometimes you may want to remove None values instead of converting them.
join() also works with tuples #
names = ("Sam", "Lee", "Mia")
print(" / ".join(names))
Output:
Sam / Lee / Mia
Common errors with join() #
Here are the most common beginner mistakes.
1. TypeError because not all items are strings #
items = ["a", 2, "c"]
print(" ".join(items))
This fails because 2 is an integer.
Fix:
items = ["a", 2, "c"]
print(" ".join(map(str, items)))
If you see an error like this, read how to fix TypeError: sequence item 0: expected str instance.
2. Calling join() on a list instead of a string #
This is wrong:
words = ["Python", "is", "fun"]
result = words.join(" ")
join() is a string method, not a list method.
Correct version:
words = ["Python", "is", "fun"]
result = " ".join(words)
print(result)
3. Using the wrong separator #
words = ["one", "two", "three"]
print("".join(words))
Output:
onetwothree
If you wanted spaces, use " " instead.
4. Forgetting that join() returns a new string #
words = ["a", "b", "c"]
"-".join(words)
print(words)
Output:
['a', 'b', 'c']
The list is unchanged because join() returns a new string. You need to store or print the result.
join() vs concatenation with + #
Both join() and + can combine strings, but they are used in different situations.
Use + for a small number of fixed strings #
first = "Hello"
second = "World"
result = first + " " + second
print(result)
Output:
Hello World
Use join() for many strings or a list of strings #
words = ["Python", "makes", "this", "easy"]
result = " ".join(words)
print(result)
Output:
Python makes this easy
join() is usually cleaner when:
- You already have a list of strings
- You want the same separator between every item
- You want to avoid writing many
+operators
For a task-focused guide, see how to join strings in Python.
Common mistakes to check #
If join() is not working, check these first:
- You may be trying to join a list that contains integers
- You may be trying to join a list that contains
None - You may have written
list.join(...)instead ofstring.join(...) - You may be expecting
join()to change the original iterable - You may have passed a non-iterable value
These quick checks can help:
print(type(items))
print(items)
print([type(item) for item in items])
print(' '.join(['a', 'b', 'c']))
print(', '.join(map(str, [1, 2, 3])))
What these checks do:
print(type(items))shows what kind of valueitemsisprint(items)shows the actual contentsprint([type(item) for item in items])shows the type of each itemprint(' '.join(['a', 'b', 'c']))confirms normaljoin()behaviorprint(', '.join(map(str, [1, 2, 3])))shows how to join numbers after converting them
FAQ #
Does join() work with numbers? #
Not directly. join() needs strings. Convert numbers first, for example with map(str, values).
Does join() change the original list? #
No. It returns a new string and leaves the original list unchanged.
Can I use join() with a tuple? #
Yes. join() works with any iterable of strings, including tuples.
What does ''.join(words) do? #
It joins the strings without adding any separator between them.
Why do I get TypeError when using join()? #
Usually because at least one item in the iterable is not a string.
See also #
- How to join strings in Python
- Python string
split()method - Python
str()function explained - Fix
TypeError: sequence item 0: expected str instance - Python strings explained: basics and examples
Once you understand join(), you can use it in real tasks like formatting full names, building comma-separated text, and combining words from a list into a single string.