Skip to content Skip to main navigation Skip to footer

python 中join方法的用法

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

>>> name='lizhanguo wangyuwei lixuehan'
>>> a = name.split()
>>> a
['lizhanguo', 'wangyuwei', 'lixuehan']
 
>>> b = ','.join(a)   注:以逗号分隔
>>> b
'lizhanguo,wangyuwei,lixuehan'
 
>>> c = ' '.join(a)    注:以空格分隔
>>> c
'lizhanguo wangyuwei lixuehan'
 
0 Comments

There are no comments yet

Leave a comment

Your email address will not be published.