.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 theiterable
. - The
iterable
is any object that can be iterated over like tuples or lists. All values of theiterable
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:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.