Home > Backend Development > Python Tutorial > Python 连接字符串(join %)

Python 连接字符串(join %)

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-16 08:47:35
Original
1308 people have browsed it

join 方法用于连接字符串数组

复制代码 代码如下:

s = ['a', 'b', 'c', 'd']
print ''.join(s)
print '-'.join(s)

输出结果:
abcd
a-b-c-d

使用 % 连接多个变量
复制代码 代码如下:

a = 'hello'
b = 'python'
c = 1
print '%s %s %s %s' % (a, b, c, s)

输出结果:
hello python 1 ['a', 'b', 'c', 'd']
Related labels:
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