The join() method is a string method and returns a string in which the elements of sequence have been joined by str separator.
Syntax:
string_name.join(iterable)
string_name: It is the name of string in which
joined elements of iterable will be
stored.
Parameters: The join() method takes iterable – objects capable of returning its members one at a time. Some examples are List, Tuple, String, Dictionary and Set
Return Value: The join() method returns a string concatenated with the elements of iterable.
Type Error: If the iterable contains any non-string values, it raises a TypeError exception.
Below program illustrates the working of join() method:
# Python program to demonstrate the # use of join function to join list # elements with a character. list1 = ['1','2','3','4'] s = "-" # joins elements of list1 by '-' # and stores in sting s s = s.join(list1) # join use to join a list of # strings to a separator s print(s) |
Output:
1-2-3-4
Joining with empty string.
# Python program to demonstrate the # use of join function to join list # elements without any separator. # Joining with empty separator list1 = ['g','e','e','k', 's'] print("".join(list1)) |
Output:
geeks
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- Python | Pandas str.join() to join string/list elements with passed delimiter
- numpy string operations | join() function
- Python String Methods | Set 2 (len, count, center, ljust, rjust, isalpha, isalnum, isspace & join)
- Python program to split and join a string
- Python | Merge, Join and Concatenate DataFrames using Panda
- Python | Join tuple elements in a list
- Python | os.path.join() method
- Python | Ways to join pair of elements in list
- Python | Join cycle in list
- Python - Consecutive K elements join in List
- Python MySQL - Join
- Python - Join Tuples to Integers in Tuple List
- Python - Join Tuples if similar initial element
- Python Program to perform cross join in Pandas
- Python - Cross Join every Kth segment
- Join two text columns into a single column in Pandas
- Tableau - Join databases
- How to Join Pandas DataFrames using Merge?
- Python - Call function from another function
- Wand function() function in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
