Discuss / Python / 各位大神给看一下哪里错了呢

各位大神给看一下哪里错了呢

Topic source

bigbigbigbook

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

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

丶姆路

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

編-9527

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

这样也不对啊,提示s[1:]是无效的语法


  • 1

Reply