Python连接字符串(join%)
来源:动视网
责编:小采
时间:2020-11-27 14:29:21
Python连接字符串(join%)
Python连接字符串(join%):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
导读Python连接字符串(join%):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

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']
Python连接字符串(join%)
Python连接字符串(join%):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