all Python 3Strings (str)function
str.join
union
Concatenate an iterable of strings using the string as the separator.
Syntax
sep.join(iterable)
The separator is the string you call the method on: it is ','.join(items), never items.join(','), and that inversion trips up most beginners. join does no conversion — an iterable of ints raises TypeError, so wrap it in map(str, ...) first. Building a string with += in a loop rebuilds it on every step, while join walks the sequence and allocates the result once.
Examples
print(','.join(['a', 'b', 'c'])) # → a,b,c
print(''.join(['1', '2', '3'])) # → 123
print('-'.join('abc')) # → a-b-c
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy