def trim(s):
start = 0
while s[start:start+1] == ' ':
start = start + 1
end = -1
while s[end:] == ' ':
end = end - 1
if end == -1:
end = 0
ends = len(s) + end
news = s[start:ends]
print(f'开始截取索引:{start}, 结束索引位置:{ends}, 去掉空格的值为: {news}')
return news
Sign in to make a reply
一把破木吉他
def trim(s):
start = 0
while s[start:start+1] == ' ':
start = start + 1
end = -1
while s[end:] == ' ':
end = end - 1
if end == -1:
end = 0
ends = len(s) + end
news = s[start:ends]
print(f'开始截取索引:{start}, 结束索引位置:{ends}, 去掉空格的值为: {news}')
return news