def trim(s):
while s[:1]==' ':
s = trim(s[1:])
while s[-1:]==' ':
s = trim(s[:-1])
return s
C:\Users\Queen\Desktop\di>python
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
from new import trim
trim(' hello')
'hello'
trim(' hello')
'hello'
嘻嘻哈哈12345666
-- coding: utf-8 --
def trim(s): while s[:1]==' ': s = trim(s[1:]) while s[-1:]==' ': s = trim(s[:-1]) return s
C:\Users\Queen\Desktop\di>python Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.