Discuss / Python / 做作业

做作业

Topic source

Rayn-S

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

求更简洁的……

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

  • 1

Reply