题目链接:
https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001431756919644a792ee4ead724ef7afab3f7f771b04f5000
正确实践
# -*- coding: utf-8 -*-
def trim(s):
if 0==len(s):
return s
while ' '==s[0]:
s=s[1:]
if 0==len(s):
return s
while ' '==s[-1]:
s=s[:-1]
return s
#思路尝试,return 不能返回去除空格的格式结果
def trim(s):
return s
#思路尝试,s=s[1:]去除了前面的所有空格的格式结果
# -*- coding: utf-8 -*-
def trim(s):
while ' '==s[0]:
s=s[1:]
return s