Python String join() Method

Joins an array of strings with the specified string.

Syntax

Python
string.join(iterable)

Parameters

ParameterDescription
iterable Required. An iterable object that returns strings.

Example

Python
str = '-'.join(('Hello', 'World'))
print(str)

Output

Hello-World

Notes: Any "iterable" object such as a list, tuple, dictionary, or set is iterable.

Example of joining a dictionary. Note that the keys are joined, not the values:

Python
fields = {'salePrice':49, 'discount': .5}
print('*'.join(fields))

Output

salePrice*discount