现在的位置: 首页 > 综合 > 正文

python split

2013年02月17日 ⁄ 综合 ⁄ 共 304字 ⁄ 字号 评论关闭

split 是非常重要的字符串方法,它是join的逆方法,用来将字符串分割成序列

>>> '1+2+3+4+5'.split('+')
['1', '2', '3', '4', '5']
>>> 'usr/bin/env'.split('/')
['usr', 'bin', 'env']
>>> 'usr/bin/env'.split('/')
['usr', 'bin', 'env']
>>> '/usr/bin/env'.split('/')
['', 'usr', 'bin', 'env']
>>> 'using the default'.split()
['using', 'the', 'default']

如果不提供任何分隔符,程序会把所有空格作为分隔符

抱歉!评论已关闭.