Python String join() Method

Advertisements


Description

The method join() returns a string in which the string elements of sequence have been joined by str separator.

Syntax

Following is the syntax for join() method:

str.join(sequence)

Parameters

  • sequence -- This is a sequence of the elements to be joined.

Return Value

This method returns a string, which is the concatenation of the strings in the sequence seq. The separator between elements is the string providing this method.

Example

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

#!/usr/bin/python

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

Let us compile and run the above program, this will produce the following result:

a-b-c



Advertisements
Advertisements