Python String join() Methods


Contents

Description

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.

Syntax

Below is the syntax for join() method:

str.join(sequence)

Parameters

  • sequence − It is the sequence of the elements that are to be joined.

Return Value

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.

Example

The example below shows the usage of join() method.

#!/usr/bin/python

s = "-";
seq = ("a", "b", "c"); # This is sequence of strings.
print s.join( seq )

When the above program is run, it produces following result:

a-b-c

Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.



Navigation
Tutorial
Tutorial
Tutorial