Python String join() Method
Joins an array of strings with the specified string.
Syntax
Python
Copy Code
string.join(iterable)
Parameters
Parameter | Description |
---|---|
iterable |
Required. An iterable object that returns strings. |
Example
Python
Copy Code
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
Copy Code
fields = {'salePrice':49, 'discount': .5} print('*'.join(fields))
Output
salePrice*discount