Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python3 join() Method

Python3 join() Method

Python3 Strings Python3 Strings


Description

The Python join() method joins the elements of a sequence with a specified character to generate a new string.

Syntax

Syntax of the join() method:


str.join(sequence)

Parameters

Return Value

Returns the new string generated by joining the elements of the sequence with the specified character.

Example

The following example shows how to use join():

Example

#!/usr/bin/python3

s1

=

"-"

s2

=

""

seq

=

(

"r"

,

"u"

,

"n"

,

"o"

,

"o"

,

"b"

)

String sequence

print

(

s1.

join

(

seq

)

)

print

(

s2.

join

(

seq

)

)

The output of the above example is:


r-u-n-o-o-b
runoob

Python3 Strings Python3 Strings