.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.
Learn Python on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours