Discuss / Python / nice 如果不用递归就好了

nice 如果不用递归就好了

Topic source

自己调试的话 可以把题目的空格改成'*',这样会方便自己看结果

def trim(s):
    l=len(s)
    print(l)
    if(s==''):
        return s
    if(s[0]==' '):
        return(trim(s=s[1:l]))
    if(s[l-1]==' '):
        return(trim(s=s[0:l-1]))
    if((s[0]!=' ') & (s[l-1]!=' ')):
        print(s)
        return s

-


  • 1

Reply