TA贡献1811条经验 获得超4个赞
用re.sub直接替换空格感觉更方便些
import re text = "I am an handsome boy" print(re.sub(r'\s+', '', text))
TA贡献1891条经验 获得超3个赞
递归忘了写返回,在判断s[0]==" "时,要reutrn ltrim(s)
s[0]==" "
reutrn ltrim(s)
举报