Discuss / Python / 最完美且永不报错的方法

最完美且永不报错的方法

Topic source

Terser

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

最完美且永不报错的方法:

def trim(s):
    if s != '':
        while s[0] == ' ' and len(s) > 1:
            s = s[1:]
        while s[-1:] == ' ' and len(s) > 1:
            s = s[:-1]
        if s == ' ':
            s = ''
    return s

学到了 0v0


  • 1

Reply