The join() method in Python String returns a string where the string elements of the sequence are joined by str separator. Thus, it is a method that returns a string which is concatenated within the elements of an iterable. The join() method in Python string thus provides a flexible path to concatenate the string. It concatenates every element of the iterable (like as list, string as well as tuple) to the string and further returns the concatenated string.
Below is the syntax for join() method:
- sequence − It is the sequence of the elements that are to be joined.
This method returns a string, which refers to the concatenation of the strings within the sequence seq. The separator of the elements is the string that provides this method.
The example below shows the usage of join() method.
s = "-";
seq = ("a", "b", "c"); # This is sequence of strings.
print s.join( seq )
When the above program is run, it produces following result:
Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.