Discuss / Python / 每一次判断完成采用递归方式对字符串继续检测以免漏删‘ ’的情况

每一次判断完成采用递归方式对字符串继续检测以免漏删‘ ’的情况

Topic source

阿财

#1 Created at ... [Delete] [Delete and Lock User]
def trim(s):    if len(s)==0:        return ''    else:        if s[0]==' ':            s=s[1:]            return trim(s)        if s[-1]==' ':            s=s[:len(s)-1]            return trim(s)    return s

  • 1

Reply