Discuss / Python / 摆脱不了C语言的思路。

摆脱不了C语言的思路。

Topic source
def trim(s):
n = 0
while n <= len(s):
  if s[n:n+1] != ' ':
    s = s[n:]
  break
  n = n+1
n = -1
while n > -len(s):
  if s[n-1:n] != ' ':
    if n==-1:
    s = s[-len(s):]
    else:
    s = s[-len(s):n]
  break
n=n-1
return s


  • 1

Reply