利用切片操作,实现一个trim()函数,去除字符串首尾的空格
>>> def trim(s):
... if len(s)==0:
... return s
... else:
... while s[0]==' ':
... s=s[1:]
... while s[-1]==' ':
... s=s[0:-1]
... return s