.join()

Published Mar 18, 2022
Contribute to Docs

The .join() method concatenates all items from an iterable into a single string.

Syntax

The .join() method is called on a separator string:

string.join(iterable)
  • The separator can be any string, even an empty one, and is placed between each element from the iterable.
  • The iterable is any object that can be iterated over like tuples or lists. All values of the iterable must be strings.

Example

The following example returns a string version of the fruits list, separated by a single space (" "):

fruits = ["Apples", "Bananas", "Blueberries"]
combined = " ".join(fruits)
print(combined)
# Output: Apples Bananas Blueberries

Codebyte Example

Using .join() to append elements of a tuple with a dash ("-") as a separator:

Code
Output
Loading...

All contributors

Looking to contribute?

Learn Python on Codecademy