def trim(s):
start = 0
end = len(s)
while start<end and s[start]==' ':
start = start +1
while start <end and s[end-1]==' ':
end = end-1
return(s[start:end])
while True:
if s[:1]==' ':
s=s[1:]
elif s[-1:]==' ':
s=s[:-1]
else:
break
return s
这样行不行
Sign in to make a reply
RaidriarF
def trim(s):
start = 0
end = len(s)
while start<end and s[start]==' ':
start = start +1
while start <end and s[end-1]==' ':
end = end-1
return(s[start:end])