Python String join() Method

Example

Use the hash character as a separator to concatenate all items in the tuple into a string:

myTuple = ("Bill", "Steve", "Elon")
x = "#".join(myTuple)
print(x)

Run Instance

Definition and Usage

The join() method retrieves all items from the iterable and concatenates them into a string.

The string must be specified as the separator.

Syntax

string.join(iterable)

Parameter Value

Parameter Description
iterable Required. Any iterable that returns a string.

More Examples

Example

Use the word "TEST" as a separator to concatenate all items in the dictionary into a string:

myDict = {"name": "Bill", "country": "USA"}
mySeparator = "TEST"
x = mySeparator.join(myDict)
print(x)

Run Instance

Note: When using a dictionary as an iterator, the returned value is the key, not the value.