if len(s)>0: if s[0]!=" " and s[-1]!=" ": return s elif s[0]==" ": s=s[1:] return trim(s) elif s[-1]==" ": s=s[:-1] return trim(s) else: return s
用递归来做的核心就一定要在第一句把满足所有条件的结果返回。而不仅仅是一边满足。
Sign in to make a reply
筱枫_Edward
if len(s)>0: if s[0]!=" " and s[-1]!=" ": return s elif s[0]==" ": s=s[1:] return trim(s) elif s[-1]==" ": s=s[:-1] return trim(s) else: return s