Discuss / Python / 递归递归

递归递归

Topic source

def trim(s): if s[0] !=' ' and s[-1] != ' ': return s elif s[0] == ' ': s=s[1:] if s[-1] == ' ': s = s[:-2] return trim(s) return trim(s)

def trim(s): if len(s) == 0 or (s[0] !=' ' and s[-1] != ' ') : return s elif s[0] == ' ': s=s[1:] if s[-1] == ' ': s = s[:-2] return trim(s) return trim(s) else: if s[-1] == ' ': s = s[:-2] return trim(s)


  • 1

Reply