The join Method in Python: Concatenating Elements into a String

Returns a string constructed from elements of an iterable object that supports iteration.

join(iterable)

  • iterable — an iterable object whose elements are joined into a string.

The string object providing this method is used as the separator between elements.

dots = '..'
dots.join(['1', '2'])  # '1..2'
dots.join('ab')  # 'a..b'

The iterable object must yield strings. To convert elements to strings, use the map() function:

dots.join(map(str, [100, 200]))  # '100..200'