.join()

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...

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn Python on Codecademy