Discuss / Python / 练习

练习

Topic source

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

def trim(s):

    lenth = len(s)

    st = 0

    while ((st < lenth) and (s[st] == ' ')):

        st = st + 1

    while ((st < lenth) and (s[lenth-1] == ' ')):

        lenth = lenth - 1

    if (st > 0) or (lenth < len(s)):

        return s[st:lenth]

    return s


  • 1

Reply