Discuss / Python / 作业

作业

Topic source

JoyElaine

#1 Created at ... [Delete] [Delete and Lock User]

def trim(s): a=len(s) n=0 m=1 while n<a: if s[n] !=' ': b=n break n=n+1 while m<a: if s[-m] !=' ': c=a-m+1 break m=m+1 return s[b:c] print(trim('hello ')) print(trim(' hello')) print(trim(' hello ')) print(trim(' hello world '))

hello hello hello hello world


  • 1

Reply