Discuss / Python / 练手

练手

Topic source

岁益寒

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

def trim(s):

    n=len(s)

    if n<=0:

        return s

    while n>0:

        if not (s[0]==' ') | (s[-1]==' '):

            break

        if s[0]==' ':

            s=s[1:]

            n-=1

        if s[-1]==' ':

            s=s[0:-1]

            n-=1

    return s


  • 1

Reply