def trim(s): n = len(s) if s[:1] == " ": #去掉头部空格 s=s[-n+1:] return trim(s) elif s[-1:] == " ": #去掉尾部空格 s=s[:n-1] return trim(s) None #去掉中间的? return s print(trim(" hello "))
Sign in to make a reply
虾米阿栋
-- coding: utf-8 --
def trim(s): n = len(s) if s[:1] == " ": #去掉头部空格 s=s[-n+1:] return trim(s) elif s[-1:] == " ": #去掉尾部空格 s=s[:n-1] return trim(s) None #去掉中间的? return s print(trim(" hello "))