Discuss / Python / 11

def trim(s): n = len(s) for i in range(n): if ord(s[i]) != 32: a = i s = s[i:] break for i in range(n-1,-1,1): if ord(s[i]) != 32: s = s[:i] break
return s

#上面a=i多余

def trim(s): n = len(s) for i in range(n): if ord(s[i]) != 32: s = s[i:] break for i in range(n-1,-1,1): if ord(s[i]) != 32: s = s[:i] break
return s


  • 1

Reply