Let us learn what is Python Join function and how to implement the Python string join() method in multiple ways with examples, explanation and much more.
What is Python Join() Method?
In simplest words, the join() method is nothing but a way to concatenate two different strings, tuples or a list.
This join() method returns a concatenated string with the sequence separated the delimiter (or the separator). A sequence could be a list, tuple, dictionary or even a set.
For instance, if your string is something like “ABC” and the separator is “-“, the final output would be “A-B-C”. This is simple and straight forward.
The join() function returns a string concatenated with the elements of the sequence as well as the delimiter. If the string contains any non-string values, it raises a TypeError exception.
Syntax
1 | string.join(string_values) |
- string: This is the string defined with the delimiter or the separator.
- string_values: This is the string defined which needs to be separated by the delimiter. This could be anything such as list, tuple, set or dictionary.
Example 1: Python Join() method with Delimiter using String
Here, we’re joining two strings in Python using the join() function. We’re using Python join with Delimiter –, and we’re capturing the join functionality within a new string which incorporates the delim within the str, and returns the results.
1 2 3 4 5 6 7 | >>> >>> str = "CodingAlpha" >>> delim = "-" >>> new_string = delim.join(str) >>> new_string 'C-o-d-i-n-g-A-l-p-h-a' >>> |
Example 2: Python Join() method using Tuple
Here, we’re joining two strings in Python using the join() function. This is similar to the above example; the only difference is that the string is Tuple in this case.
1 2 3 4 5 6 7 8 | >>> >>> demoTuple = ("Coding","Alpha") >>> delim = "$" >>> newTuple = delim.join(demoTuple) >>> newTuple 'Coding$Alpha' >>> >>> |
Example 3: Python Join() method using the List of Integers
Here, we’re joining two lists in Python using the join() method. This is similar to the above example; the only difference is that the Tuple is List in this example.
1 2 3 4 5 6 7 8 | >>> >>> demoList = ['1','2','3','4'] >>> delim = '@' >>> new_list = delim.join(demoList) >>> new_list '1@2@3@4' >>> >>> |

If you have any doubts about Python Join function, let us know about it in the comment section. For more insights on Python string functions, you can check the documentation.
More Python Programs
- Python Find() method
- Search a string within another string in Python
- How To Setup Python Database Connection
- range() Method in Python
- Python sleep() Method
- Send Email in Python using SMTP
- Vernam Cipher Python Code