Discuss / Python / 练习

练习

Topic source

😶

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

def trim(s):

    x = 0

    c = -1

    for i in s:

        if s[x] == " ":

            x += 1

        else:

            break

    for i in s:

        if s[c] == " ":

            c += -1

        else:

            break

    if c == -1:

        n = s[x:]

    elif c != -1:

        n = s[x:c + 1]

    print(x,c,n)

    return n

有梦不难

#2 Created at ... [Delete] [Delete and Lock User]
# -*- coding:utf-8 -*-def trim(s):    if s=='':        return s    while s[0]==' ':        s=s[1:]        if s=='':            return s    while s[-1]==' ':        s=s[:-1]    return s

有梦不难

#3 Created at ... [Delete] [Delete and Lock User]
# -*- coding:utf-8 -*-def trim(s):    if s=='':        return s    while s[0]==' ':        s=s[1:]        if s=='':            return s    while s[-1]==' ':        s=s[:-1]    return s

  • 1

Reply