python 中join方法的用法

在Python语言里如何来使用join方法呢?下面举几个例子:

1
2
3
4
>>> name='lizhanguo wangyuwei lixuehan'
>>> a = name.split()
>>> a
['lizhanguo', 'wangyuwei', 'lixuehan']
1
2
3
>>> b = ','.join(a)   注:以逗号分隔
>>> b
'lizhanguo,wangyuwei,lixuehan'
1
2
3
>>> c = ' '.join(a)    注:以空格分隔
>>> c
'lizhanguo wangyuwei lixuehan'
Sidebar