Discuss / Python / 哈

虾米阿栋

#1 Created at ... [Delete] [Delete and Lock User]

-- 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 "))


  • 1

Reply