Discuss / Python / 最初的想法(略显笨拙)

最初的想法(略显笨拙)

Topic source
def trim1(s):    length = len(s)    begin=0    end=-1    while begin<length and s[begin]==" ":        begin+=1    while -end < length and s[end]==" ":        end-=1    if begin-end<=length:        if end==-1:            return s[begin:]        else:            return s[begin:end+1]    return ""

  • 1

Reply