Python Function Reference

str.join

Join the strings of an iterable, inserting the original string between them.

Python 3.13
str.join(iterable)

Parameters

iterableIterable
The strings to join.

Return value

A new string; raises TypeError if some items are not strings.

Examples

Joining words with a space

Python 3.13
print(' '.join(['hello', 'world']))
hello world

Joining numbers

Python 3.13
print(', '.join(map(str, [1, 2, 3])))
1, 2, 3

Details

Convert numbers to strings first, for example with map(str, numbers).

See also

Where to learn