Master Code
On The Go

Learn. Practice. Build.

Home › Code Snippets › Python › Reference › join()

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.

Input:

                
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
iterableiterable of strStrings to join. Non-strings raise TypeError.
1

Basic Join

" ".join(["Hello", "World"])
# 'Hello World'

"-".join(["2026", "10", "11"])
# '2026-10-11'

",".join(["a", "b", "c"])
# 'a,b,c'
2

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.

3

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.

4

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.

5

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
joinO(n)Joining many strings from an iterable
+O(n²) in loopOnly for 2-3 strings
f-stringFastInterpolating variables into templates
formatFastReusing templates (pre-3.6 style)

⚠️ Common Mistakes

❓ 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.

🎯 What's Next?

← All Python Reference