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

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

WBOY
Release: 2016-06-06 11:16:49
Original
1583 people have browsed it

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

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

str.join(sequence)

Copy after login

参数

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

返回值

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

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

#!/usr/bin/python

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

Copy after login

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

a-b-c

Copy after login

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template