您的位置:首页 > 编程语言 > Python开发

python3----连接字符串数组(join)

2018-01-11 20:07 295 查看

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

1 s = ['a', 'b', 'c', 'd']
2 print(''.join(s))
3 print('-'.join(s))
4
5 results:
6
7 abcd
8 a-b-c-d

 

使用 % 连接多个变量

1 a = 'hello'
2 b = 'python'
3 c = 1
4 print('%s %s %s %s' % (a, b, c, s))
5
6 results:
7
8 hello python 1 ['a', 'b', 'c', 'd']

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: