Does a Python strip() on a split() string do anything?

风格不统一 提交于 2019-12-01 18:34:40

The documents indicate that split with the implicit whitespace delimiter (that is, split() without further arguments) will clear out any "empty tokens" and you don't need to strip anything. As any consecutive series of whitespace could be interpreted as a list of empty tokens delimited by space, that'll mean the strings get trimmed automatically.

If, instead you split with a different delimiter or implicitly defined the whitespace, this may happen:

' 1  2   3  '.split()
=> ['1', '2', '3']

'  1  2   3  '.split(None, 1)
=> ['1', '2   3  ']
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!