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

split python

2013年12月10日 ⁄ 综合 ⁄ 共 199字 ⁄ 字号 评论关闭

print re.split(r'\s+','a b   c d e   f') #['a', 'b', 'c', 'd', 'e', 'f']

print 'a b   c d e   f'.split(' ') #['a', 'b', '', '', 'c', 'd', 'e', '', '', 'f']

print 'a b   c d e   f'.split() #['a', 'b', 'c', 'd', 'e', 'f']

 

其中b和c之间,e和f之间由多个空格分开,结果如注释所示

抱歉!评论已关闭.