Discuss / Python / 字符串去头尾空格

字符串去头尾空格

Topic source

虫二YCY

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

-- coding: utf-8 --

**def trim(s):

start=0
end=len(s)-1
while start < end:
    if s[start]==' ':
        start=start+1
    elif s[end] ==' ':
        end=end-1
    else:
        break
if start>=end:
    return ''
else:
    return s[start:end+1]

鲱鱼菌

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

大神好厉害


  • 1

Reply