def trim(s): if not s: return s # 去除左边的空格 left_index = 0 while left_index < len(s) and s[left_index] == ' ': left_index += 1 # 去除右边的空格 right_index = len(s) - 1 while right_index >= 0 and s[right_index] == ' ': right_index -= 1 # 返回处理后的字符串 return s[left_index:right_index + 1]
Sign in to make a reply
C❤️M