PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

Python 连接字符串(join %)

原创
2016-06-16 08:47:35 1013浏览

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']
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。