def trim(s)
if len(s)!=0:
while s[:1]==' ':
s=s[1:]
while s[-1:]==' ':
s=s[:-1]
return s
else:
s=''
print(trim('hello '))
print(trim(' hello'))
print(trim(' hello world '))
Sign in to make a reply
cktlee_312
def trim(s)
if len(s)!=0:
while s[:1]==' ':
s=s[1:]
while s[-1:]==' ':
s=s[:-1]
return s
else:
s=''
return s
print(trim('hello '))
print(trim(' hello'))
print(trim(' hello world '))