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

nice 如果不用递归就更好了

Topic source
# -*- coding: utf-8 -*-

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