python 中join方法的用法

在Python语言里如何来使用join方法呢?下面举几个例子:
[cc lang=”python”]
>>> name=’lizhanguo wangyuwei lixuehan’
>>> a = name.split()
>>> a
[‘lizhanguo’, ‘wangyuwei’, ‘lixuehan’]
[/cc]
[cc lang=”python”]
>>> b = ‘,’.join(a) 注:以逗号分隔
>>> b
‘lizhanguo,wangyuwei,lixuehan’
[/cc]
[cc lang=”python”]
>>> c = ‘ ‘.join(a) 注:以空格分隔
>>> c
‘lizhanguo wangyuwei lixuehan’
[/cc]

Leave a Reply