def trim(s): while s[:1]==' ': s=s[1:] while s[-1:]==' ': s=s[:-1] return s print(trim('hello ')) print(trim(' hello')) print(trim(' hello ')) print(trim(' hello world ')) print(trim(' '))
Sign in to make a reply
独具一格5
def trim(s): while s[:1]==' ': s=s[1:] while s[-1:]==' ': s=s[:-1] return s print(trim('hello ')) print(trim(' hello')) print(trim(' hello ')) print(trim(' hello world ')) print(trim(' '))