Discuss / Python / 作业

作业

Topic source

燕喜泥润

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

def trim(s):

    if s == '':

        return ''

    elif s[0] == ' ':

        s = trim(s[1:])

    elif s[-1] ==  ' ':

        s = trim(s[:-1])

    return s

    if s == '':

        return ''

请问一下为什么要加这一句话

def trim(s):

    if s[:1] == ' ':

        return trim(s[1:])

    if s[-1:] == ' ':

        return trim(s[:-1])

    else:

        return s   

这一段程序里就不需要这个  一直没想明白


  • 1

Reply