Python3 join() Method

Python3 字符串Python3 Strings


Description

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

Syntax

join() method syntax:

str.join(sequence)

Parameters

  • sequence -- The sequence of elements to be joined.

Return Value

Returns a new string generated by connecting the elements in the sequence with the specified character.

Example

The following example demonstrates 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
example

Python3 字符串Python3 Strings

Other Extensions