def trim(s):
if s:
while len(s) != 0 and s[0] == ' ':
s = s[1:]
while s[-1] == ' ':
s = s[:-1]
return s
作业中while判断条件‘ ’ 之间是有空格的
Sign in to make a reply
_JasonTong
def trim(s):
if s:
while len(s) != 0 and s[0] == ' ':
s = s[1:]
if s:
while s[-1] == ' ':
s = s[:-1]
return s