Easy Tutorial
❮ Python File Methods Python Namespace Scope ❯

Python3 join() Method

Python3 Strings


Description

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

Syntax

The syntax for the join() method is:

str.join(sequence)

Parameters

Return Value

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

Example

The following example demonstrates the use of the join() method:

#!/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

❮ Python File Methods Python Namespace Scope ❯