str.join() Join iterable
Last updated: 2026-09-22
str.join() Join iterable
str.join(iterable) joins strings from iterable using str as separator.
| Category | String Methods |
|---|---|
| Kind | Built-in Type Method |
| Python Version | all |
📝 Syntax
str.join(iterable)
⚙️ Parameters
| iterable Required | An iterable of strings, e.g. a list, tuple, or generator. |
|---|
Returns:str. The elements joined with the string as a separator.
Mutates the original:No (returns a new object)
💥 Raises
TypeError— Raised when the iterable contains a non-string element.
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
a, b, c
a-b-c
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhat happens when the list contains numbers?
AA TypeError is raised; join() only accepts string elements. You must convert first: ','.join(map(str, [1, 2, 3])).
QWhen concatenating many strings, is join() or + faster?
Ajoin() is clearly faster because it allocates memory once; repeated += concatenation in a loop is O(n²). Prefer join() when concatenating a list of strings.
QWhat does joining with an empty separator do?
A''.join(['a', 'b', 'c']) is equivalent to directly producing 'abc', often used to combine a list of characters into a string.
QWhat happens when calling join() on an empty list?
AIt returns the empty string '', without raising an error.