Python Reference
str.join()
Join an iterable of strings into one string. Reverse of split.
Last updated: October 2026
join() combines an iterable of strings into one string, using the string it's called on as the separator. It's the reverse of split().
Full definition: str.join(iterable) concatenates the elements of an iterable into a single string. All elements must be strings — non-strings raise TypeError. It returns a new string and does not modify the iterable.
🎬 Live Example
Five common join patterns. Click any button to see the output.
💡 join is the reverse of split. Use it whenever you need to concatenate many strings.
Basic Syntax
separator.join(iterable)
# separator — the string to place between elements
# iterable — any iterable of strings
# Returns: new str
# Does NOT modify the original
🎯 Parameters
| Parameter | Type | Description |
|---|---|---|
iterable | iterable of str | Strings to join. Non-strings raise TypeError. |
Basic Join
" ".join(["Hello", "World"])
# 'Hello World'
"-".join(["2026", "10", "11"])
# '2026-10-11'
",".join(["a", "b", "c"])
# 'a,b,c'
Empty Separator
"".join(["a", "b", "c"])
# 'abc'
"".join(["Hello", " ", "World"])
# 'Hello World'
Pro tip: "".join() is the fastest way to concatenate a list of strings.
Join Integers (Convert First)
# ❌ Raises TypeError
",".join([1, 2, 3])
# ✅ Convert to strings first
",".join(map(str, [1, 2, 3]))
# '1,2,3'
",".join(str(x) for x in [1, 2, 3])
# '1,2,3'
Remember: join requires strings. Convert non-strings with map(str, ...) or a generator.
join vs + (Performance)
# ❌ SLOW — O(n²) for large lists
result = ""
for word in words:
result += word
# ✅ FAST — O(n)
result = "".join(words)
Always use join when concatenating more than a few strings. It's dramatically faster for large data.
Real-World: Build URL Path
parts = ["api", "users", "42"]
path = "/" + "/".join(parts)
# '/api/users/42'
# Build CSV line
row = ["Alice", "30", "Engineer"]
line = ",".join(row)
# 'Alice,30,Engineer'
# Reverse of split
",".join("a,b,c".split(","))
# 'a,b,c' (back to original)
🎯 join vs + vs f-string vs format
| Method | Speed | Use when |
|---|---|---|
join | O(n) | Joining many strings from an iterable |
+ | O(n²) in loop | Only for 2-3 strings |
f-string | Fast | Interpolating variables into templates |
format | Fast | Reusing templates (pre-3.6 style) |
⚠️ Common Mistakes
- Joining non-strings. Raises TypeError. Convert with
map(str, ...). - Using join with a variable separator incorrectly. The separator is the string before the dot.
- Using + in a loop. O(n²) performance — always prefer join.
- Forgetting join is str method, not list method. Use
separator.join(list), notlist.join(separator). - Assuming join modifies the list. It returns a new string.
❓ Frequently Asked Questions
What does join() do in Python?
str.join(iterable) concatenates the elements of an iterable into a single string, using the string it was called on as the separator. It returns a new string and does not modify the iterable.
What is the difference between join and +?
+ creates a new string each time, which is O(n²) in a loop. join builds one string in O(n) and is significantly faster for joining many strings.
Does join work on lists of integers?
No. join requires all elements to be strings. Convert first: ''.join(str(x) for x in [1, 2, 3]) or use map: ''.join(map(str, [1, 2, 3])).
What is the separator for join?
The separator is the string you call join on. '-'.join(['a', 'b']) returns 'a-b'. ''.join(['a', 'b']) returns 'ab' with no separator.
Does join modify the original list?
No. join returns a new string. The original iterable is unchanged.