Discuss / Python / zuoye

zuoye

Topic source

霍墨

#1 Created at ... [Delete] [Delete and Lock User]
def trim(s):
    if s[:1]==' ':
        return trim(s[1:])
    if s[-1:] == ' ':
        return trim(s[:-1])
    return s

ts = input("Have a try:")
print(trim(ts))

这应该是最符合这章的答案了,不过最后两句可以直接删掉,没啥意义。。

简洁

人人仁勇

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

还有递归函数,不错


  • 1

Reply