Home  >  Article  >  Backend Development  >  浅析Python中的join()方法的使用

浅析Python中的join()方法的使用

WBOY
WBOYOriginal
2016-06-06 11:16:491536browse

 join()方法方法返回一个在序列的字符串元素被加入了由str分隔的字符串。
语法

以下是join()方法的语法:

str.join(sequence)

参数

  •     sequence -- 这是要连接的元素的顺序。

返回值

此方法返回一个字符串,在序列seq字符串的连接。元素之间的分离器是字符串 str。
例子

下面的示例演示了join()方法的使用。

#!/usr/bin/python

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

当我们运行上面的程序,它会产生以下结果:

a-b-c

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn