if s[:1] == ' ' and s[-1:] == ' ':
return trim(s[1:-1])
elif s[:1] == ' ':
return trim(s[1:])
elif s[-1:] == ' ':
return trim(s[:-2])
else:
return s
这个方法代码最简洁,好厉害
Sign in to make a reply
不知火舞舞舞舞舞
if s[:1] == ' ' and s[-1:] == ' ':
return trim(s[1:-1])
elif s[:1] == ' ':
return trim(s[1:])
elif s[-1:] == ' ':
return trim(s[:-2])
else:
return s