THE WORLD'S LARGEST WEB DEVELOPER SITE

Python String join() Method

❮ String Methods


Example

Join all items in a tuple into a string, using a hash tag as separator:

myTuple = ("John", "Peter", "Vicky")

x = "#".join(myTuple)

print(x)
Run example »

Definition and Usage

The join() method takes all items in an iterable and joins them into one string.

A string must be specified as the separator.


Syntax

string.join(iterable)

Parameter Values

Parameter Description
iterable Required. Any iterable object were all the returned values are strings

More Examples

Example

Join all items in a dictionary into a string, using a the word "TEST" as separator:

myDict = {"name": "John", "country": "Norway"}
mySeparator = "TEST"

x = mySeparator.join(myDict)

print(x)
Run example »

Note: When using a dictionary as an iterable, the returned values are the keys, not the values.


❮ String Methods