Discuss / Python / trim去除字符串空格函数作业提交

trim去除字符串空格函数作业提交

Topic source
# 去除字符串首尾的空格def trim(s):    while s[:1] == " ":        s = s[1:]    while s[-1:] == " ":        s = s[:-1]    return s

我是将首尾分开看待的,用while是怕有多个空格所以需要反复去除


  • 1

Reply