【发布时间】:2015-09-08 07:46:13
【问题描述】:
我开始学习python并想在空格处剪切一个字符串;所以'hello world'变成'hello'和'world'。为此,我想将空格的位置保存在列表中,但我不知道该怎么做。为了找到空间,我这样做:
def string_splitting(text):
i = 0
for i in range(len(text)):
if (text[i]==' '):
将它们保存在列表中后,我想用 text[:list[1]](或类似的东西)显示它们
谁能帮我把它保存在列表部分;这甚至可能吗?
(欢迎使用另一种截断字符串的方法:-))
谢谢。
【问题讨论】:
标签: string python-2.7 spaces